I think the generators address this issue already, to some extent. But regardless, you might be surprised to find out that this is possible already (without generators), but this is a little secret I've been holding in my pocket, all you'd have change in the example is use something else than setTimeout, and make the delay a function call instead... I'm writing a blog post about it and will be sure to share with the group. ;)
Oh and btw, if there was a keyword like this, I don't think the timeout would always occur *during* the delay, as setTimeout(..., 0) doesn't necessarily mean now, as opposed to a DOM event such as postMessage or the user clicking somewhere. Cheers, Jussi On Wed, Jul 4, 2012 at 7:19 PM, Patrik Stutz <[email protected]> wrote: > Hi guys! > > Today, a really cool idea for a new keyword in JavaScript came to my mind. > It's called 'delay'. > > What does the delay keyword ? > > The delay keyword does nothing more than stop the execution of the > current stack and immediately continues to the next task in the queue. But > that's not all! Instead of discarding the stack, it adds it to the end of > the queue. After all tasks before it are done, the stack continues to > execute. > What is it good for? > > delay could help make blocking code non-blocking while it still looks > like synchronous code. A short example: > > setTimeout(function(){ > > console.log("two"); > },0); > > console.log("one"); > > delay; //since there is currently another task in the queue, do this task > first before continuing > > console.log("three"); > > //Outputs: one, two, three > > This simple keyword would allow us to create a synchronous-looking code > wich is asynchronous behind the scenes. Using node.js modules, for example, > would no longer be impossible to use in the browser without trickery. > > There would be so many possibilites with such a keyword! > > What do YOU JAVASCRIPT DEVELOPERS think about it? What do you think can I > do to bring this into the new ECMAscript Specification? > > Please disuss as much as you want! :) > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss > >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

