Generator-based Joutube library supports Chrome browser

The Javascript generator cannot help too much since it is not a real coroutine. Therefore, I hope to have a coroutine in the browser using the new ecmascript 6 keyword, "yield". that is, I hope that I can complete a few frames in a stop lot.

As far as I know, I just found a Javascript 1.7+-based coroutine library in Firefox, which can be found at http://www.neilmix.com/2007/02/07/threading-in-javascript-17/ .

"exit" is supported in the Chrome browser for a long time. So I'm wondering if there is a coroutine implementation that supports the Chrome browser using the Javascript generator.

Thank!

+1
javascript generator coroutine google-chrome yield-keyword
04 Feb '14 at 2:57
source share
1 answer

the Q library provides an async method that completes the function of the JavaScript generator . Inside the generator function, you can asynchronously expect any Q promise object with the yield keyword, for example:

 function delay(ms) { var deferred = Q.defer(); setTimeout(deferred.resolve, ms); return deferred.promise; } function main() { var callback = Q.async(function*(){ var bodyStyle = document.body.style; yield delay(1000); bodyStyle.backgroundColor = "red"; printOutput("step 1"); yield delay(1000); bodyStyle.backgroundColor = "green"; printOutput("step 2"); yield delay(1000); bodyStyle.backgroundColor = "blue"; printOutput("step 3"); yield delay(1000); printOutput("step 4"); bodyStyle.backgroundColor = "white"; }); Q.fcall(callback).then(function (){ printOutput("Done!"); }); } 

Here is a working fiddle . Before you launch it, enable Harmony JavaScript in Chrome ( chrome://flags/#enable-javascript-harmony ).

+1
Feb 04 '14 at 4:58
source share



All Articles