I had a great idea for a new javascript keyword \"delay\", but I don\'t know wha
ID: 646249 • Letter: I
Question
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?
Explanation / Answer
It's funny that your question has been downvoted, since the feature you have described is actually the object of an official strawman1 proposal (but the actual name of the new keyword is await).
If you want to support this proposal, you can suscribe to the es-discuss mailing-list and look for the previous discussions about it.
1 Strawman is the namespace where are keeped the ES6 proposals before validation. The other one is Harmony, where are keeped the ES6 proposals which have been approved but need more work.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.