Last active
August 29, 2015 13:58
-
-
Save getify/10172207 to your computer and use it in GitHub Desktop.
Revisions
-
getify revised this gist
Jun 15, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -50,5 +50,5 @@ ASQ( 2, 3 ) } ) .val( function(msgs){ console.log( msgs[0], msgs[1] ); // 140 "Hello World" } ); -
getify revised this gist
May 28, 2014 . 1 changed file with 49 additions and 33 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,38 +1,54 @@ // just a silly number generator that's promise-async function getVal() { return new Promise( function(resolve,reject){ setTimeout( function(){ if (!getVal.__number) getVal.__number = 0; resolve( getVal.__number += 10 ); }, 100 ); } ); } // ********************** ASQ( 2, 3 ) .runner( // machine 1 function*(token){ token.messages; // [2, 3] token.messages[0] += yield getVal(); // pauses generator while promise resolves token.messages[1] += yield getVal(); // pauses generator while promise resolves token.messages.push( token.messages[0] + token.messages[1] ); token.messages; // [12, 23, 35] yield token; // hand control over to next machine token.messages; // [ 100 ] token.messages[0] += yield getVal(); // pauses generator while promise resolves // implicit finish means transfer control to next machine }, // machine 2 function*(token){ token.messages; // [12, 23, 35] token.messages = [ token.messages[0] + token.messages[1] + token.messages[2] ]; token.messages; // [ 70 ] token.messages[0] += yield getVal(); // pauses generator while promise resolves token.messages; // [ 100 ] yield token; // hand control over to next machine token.messages; // [ 140 ] token.messages.push( "Hello World" ); yield token.messages; } ) .val( function(msgs){ console.log( msg[0], msgs[1] ); // 140 "Hello World" } ); -
getify revised this gist
Apr 9, 2014 . No changes.There are no files selected for viewing
-
getify revised this gist
Apr 8, 2014 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,18 +13,18 @@ ASQ(2) // v1 will be set as `2` here function*(v1) { console.log("initial v1:" + v1); // initial v1:2 v1 += yield null; console.log("now v1:" + v1); // now v1:12 v1 += yield Pr(v1 * 2); console.log("finally v1:" + v1); // finally v1:84 yield Pr(v1 + 1); }, function*() { var v2 = yield Pr(10); console.log("initial v2:" + v2); // initial v2:24 v2 += yield Pr(v2 * 3); console.log("finally v2:" + v2); // finally v2:109 yield Pr(v2 + 6); } ) .val(function(msg){ @@ -33,6 +33,6 @@ ASQ(2) // initial v1:2 // now v1:12 // initial v2:24 // finally v1:84 // finally v2:109 // Result: 115 -
getify created this gist
Apr 8, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ // async promise wrap of value `x` function Pr(x) { return new Promise(function(resolve){ setTimeout(function(){ resolve(x); },1000); }); } // seed `2` as initial sequence message, which will pass into // first `runner` segment ASQ(2) .runner( // v1 will be set as `2` here function*(v1) { console.log("initial v1:" + v1); // initial v1:2 v1 = v1 + (yield null); console.log("now v1:" + v1); // now v1:12 v1 = yield Pr(v1 * 2); console.log("finally v1:" + v1); // finally v1:72 yield Pr(v1 + 1); }, function*() { var v2 = yield Pr(10); console.log("initial v2:" + v2); // initial v2:24 v2 = yield Pr(v2 * 3); console.log("finally v2:" + v2); // finally v2:73 yield Pr(v2 + 7); } ) .val(function(msg){ console.log("Result: " + msg); }); // initial v1:2 // now v1:12 // initial v2:24 // finally v1:72 // finally v2:73 // Result: 80