JSFiddle - React, Tailwind, and code Playground
JavaScript
// CONTAINS COPYRIGHTED CODE BECAUSE I COULDN'T INCLUDE IT WITH THE RESOURCES OPTION
/* node wait.for-ES6 - based on ES6-harmony generators
- Sequential programming for node.js - end of callback hell
- Copyright 2013 Lucio Tato
-- WARNING: bleeding edge --
This lib is based on ECMAScript 6,
the next version of the javascript standard, code-named "Harmony".
(release target date December 2013).
This lib also uses bleeding edge v8 Harmony features, so you’ll need to
use the latest -unstable- nodejs version wich today is v0.11.6
and also pass the --harmony flag when executing node.
node --harmony waitfor-demo.js
If you want to use "wait.for" but you can't use (unstable) node and/or ES6-Harmony
you can use the Fibers-based version of wait.for
at: http://github.com/luciotato/waitfor
The Fibers-based version of wait.for only requires node-fibers(stable), and node >= 0.5.2
*/
"use strict";
var Wait = {
launchFiber: function(generatorFn){ // wait.launchFiber(fn,arg1,arg2...)
//console.log(Array.prototype.slice.call(arguments));
// starts a generator (emulating a fiber)
// helper function, call the async, using theCallback as callback
function callTheAsync(FunctionAndArgs,theCallback){
// prepare arguments
var argsOnly=Array.prototype.slice.call(FunctionAndArgs,1); // remove function from args & convert to Array
argsOnly.push(theCallback); //add callback to arguments
// start the asyncFn
FunctionAndArgs[0].apply(null, argsOnly); // call the asyncFn, (strict: this=null)
}
// launchFiber :
//console.log('launchFiber',arguments);
// get parameters
var newArgs=Array.prototype.slice.call(arguments,1); // remove generatorFn from args & convert to Array
var finalCallback=null; //optional
if (typeof generatorFn !== 'function') {
if (generatorFn==='onComplete') { //1st param...