-
-
Save aponxi/f8207b30d301ce4722788952de2ed593 to your computer and use it in GitHub Desktop.
Revisions
-
victorquinn revised this gist
Dec 19, 2013 . 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 @@ -26,7 +26,7 @@ promiseWhile(function() { }, function() { // The function to run, should return a promise return new Promise(function(resolve, reject) { // Arbitrary 250ms async method to simulate async process setTimeout(function() { sum++; // Print out the sum thus far to show progress -
victorquinn renamed this gist
Dec 19, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
victorquinn revised this gist
Dec 19, 2013 . 2 changed files with 25 additions and 24 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,4 +13,28 @@ var promiseWhile = function(condition, action) { process.nextTick(loop); return resolver.promise; }; // And below is a sample usage of this promiseWhile function var sum = 0, stop = 10; promiseWhile(function() { // Condition for stopping return sum < stop; }, function() { // The function to run, should return a promise return new Promise(function(resolve, reject) { // Arbitrary 25ms async method to simulate async process setTimeout(function() { sum++; // Print out the sum thus far to show progress console.log(sum); resolve(); }, 250); }); }).then(function() { // Notice we can chain it because it's a Promise, this will run after completion of the promiseWhile Promise! console.log("Done"); }); 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,23 +0,0 @@ -
victorquinn revised this gist
Dec 18, 2013 . 1 changed file with 2 additions and 2 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,11 +1,11 @@ var Promise = require('bluebird'); var promiseWhile = function(condition, action) { var resolver = Promise.defer(); var loop = function() { if (!condition()) return resolver.resolve(); return Promise.cast(action()) .then(loop) .catch(resolver.reject); }; -
victorquinn revised this gist
Dec 18, 2013 . 1 changed file with 2 additions 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 @@ -7,7 +7,7 @@ promiseWhile(function() { // Condition for stopping return sum < stop; }, function() { // The function to run, should return a promise return new Promise(function(resolve, reject) { // Arbitrary 25ms async method to simulate async process setTimeout(function() { @@ -18,5 +18,6 @@ promiseWhile(function() { }, 250); }); }).then(function() { // Notice we can chain it because it's a Promise, this will run after completion of the promiseWhile Promise! console.log("Done"); }); -
victorquinn revised this gist
Dec 18, 2013 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
victorquinn revised this gist
Dec 18, 2013 . 2 changed files with 22 additions and 0 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 @@ -0,0 +1,22 @@ // Assuming the above gist and the Bluebird library have been included already of course... var sum = 0, stop = 10; promiseWhile(function() { // Condition for stopping return sum < stop; }, function() { // The method to run, should return a promise return new Promise(function(resolve, reject) { // Arbitrary 25ms async method to simulate async process setTimeout(function() { sum++; // Print out the sum thus far to show progress console.log(sum); resolve(); }, 250); }); }).then(function() { console.log("Done"); }); File renamed without changes. -
victorquinn renamed this gist
Dec 18, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
victorquinn created this gist
Dec 18, 2013 .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,16 @@ var Promise = require('bluebird'); var promiseWhile = function(condition, body) { var resolver = Promise.defer(); var loop = function() { if (!condition()) return resolver.resolve(); return Promise.cast(body()) .then(loop) .catch(resolver.reject); }; process.nextTick(loop); return resolver.promise; };