I have to correct myself; I just realized, you *can* actually make it a custom keyword instead of a function call. More on this later. ;)<br><br><div class="gmail_quote">On Wed, Jul 4, 2012 at 7:39 PM, Jussi Kalliokoski <span dir="ltr"><<a href="mailto:jussi.kalliokoski@gmail.com" target="_blank">jussi.kalliokoski@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think the generators address this issue already, to some extent.<br><br>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. ;)<br>

<br>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.<br>

<br>Cheers,<br>Jussi<br><br><div class="gmail_quote"><div><div class="h5">On Wed, Jul 4, 2012 at 7:19 PM, Patrik Stutz <span dir="ltr"><<a href="mailto:patrik.stutz@gmail.com" target="_blank">patrik.stutz@gmail.com</a>></span> wrote:<br>

</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><font color="#000000"><font><font face="verdana,sans-serif">Hi guys!</font></font></font><div>
<font color="#000000"><font><font face="verdana,sans-serif"><br>
</font></font></font></div><div><font face="verdana, sans-serif">Today, a really cool idea for a new keyword in JavaScript came to my mind. It's called 'delay'.</font></div>
<div><font face="verdana, sans-serif"><br></font></div><div><h2 style="vertical-align:baseline;line-height:1.3;text-align:left;font-size:19px;font-family:'Trebuchet MS','Liberation Sans','DejaVu Sans',sans-serif;margin:0px 0px 1em;border:0px;padding:0px">


What does the <code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif">delay</code> keyword ?</h2>


<p style="clear:both;vertical-align:baseline;line-height:18px;text-align:left;font-size:14px;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;margin:0px 0px 1em;word-wrap:break-word;border:0px;padding:0px">


The <code style="margin:0px;padding:1px 5px;border:0px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif">delay</code> 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.</p>


<h2 style="vertical-align:baseline;line-height:1.3;text-align:left;font-size:19px;font-family:'Trebuchet MS','Liberation Sans','DejaVu Sans',sans-serif;margin:0px 0px 1em;border:0px;padding:0px">
What is it good for?</h2><p style="clear:both;vertical-align:baseline;line-height:18px;text-align:left;font-size:14px;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;margin:0px 0px 1em;word-wrap:break-word;border:0px;padding:0px">


<code style="margin:0px;padding:1px 5px;border:0px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif">delay</code> could help make blocking code non-blocking while it still looks like synchronous code. A short example:</p>


<pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:18px;text-align:left">
<code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif"><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">setTimeout</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,139)">function</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(){</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>


    console</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">log</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"two"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>


</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">},</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">0</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>


console</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">log</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"one"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>


delay</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">;</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"> </span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">//since there is currently another task in the queue, do this task first before continuing</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>


console</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">.</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">log</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:rgb(128,0,0)">"three"</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent">);</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>


<br></span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;color:gray">//Outputs: one, two, three</span><span style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent"><br>


</span></code></pre><p style="clear:both;vertical-align:baseline;line-height:18px;text-align:left;font-size:14px;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;margin:0px 0px 1em;word-wrap:break-word;border:0px;padding:0px">


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.</p>


<p style="clear:both;vertical-align:baseline;line-height:18px;text-align:left;font-size:14px;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;margin:0px 0px 1em;word-wrap:break-word;border:0px;padding:0px">


There would be so many possibilites with such a keyword!</p><p style="clear:both;vertical-align:baseline;line-height:18px;text-align:left;font-size:14px;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;margin:0px 0px 1em;word-wrap:break-word;border:0px;padding:0px">


What do YOU JAVASCRIPT DEVELOPERS think about it? What do you think can I do to bring this into the new ECMAscript Specification?</p><p style="clear:both;vertical-align:baseline;line-height:18px;text-align:left;font-size:14px;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;margin:0px 0px 1em;word-wrap:break-word;border:0px;padding:0px">


Please disuss as much as you want! :)</p></div>
<br></div></div>_______________________________________________<br>
es-discuss mailing list<br>
<a href="mailto:es-discuss@mozilla.org" target="_blank">es-discuss@mozilla.org</a><br>
<a href="https://mail.mozilla.org/listinfo/es-discuss" target="_blank">https://mail.mozilla.org/listinfo/es-discuss</a><br>
<br></blockquote></div><br>
</blockquote></div><br>