I had a great idea for a new javascript keyword "delay", but I don't know what I can do to bring it to the new specification. Also I want to know what you guys think about it and if it's even realistic.
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 "job" in the queue. But that's not all! Instead of discarding the stack, it adds it to the end of the queue. After all "jobs" 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!
Is this pattern useful? What can I do to bring this into the new ECMAscript specification?
Note: I asked this previously
on Stack Overflow, where it was closed.