Archive for the ‘ JavaScript ’ Category

Synchronous invocation in JavaScript, part 4: error handling

Last time we saw how to transfer results of computations from pseudo-blocking calls back into the main process. What happens if when something goes wrong, though?

In the (real) synchronous world, error conditions used to travel on the same road as return values:[ READ MORE ]

Synchronous invocation in JavaScript, part 3: returning values

We've seen how to simulate a blocking sleep() in JavaScript and what happens under the hood when we do.

Another scenario where a blocking call makes a big difference in terms of clarity is requesting data from the network and suspending execution until the answer arrives:[ READ MORE ]

Synchronous invocation in JavaScript, part 1: problem and basic solution

(Update: a library based on this series is in use in SamePlace and is available here.)

Here's something most languages can do which JavaScript can't (at least when hosted in the browser):


    print("Going to bed...");
    sleep(3000);
    print("Sigh, I only slept three seconds.")

In JavaScript that would be: [ READ MORE ]