Created
August 30, 2015 21:53
-
-
Save rdtr/8eb40403fbe91cedfb5f to your computer and use it in GitHub Desktop.
setTimeout sequeitial
This file contains 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 characters
# node --harmony sequential_timeout.js | |
# need to install co | |
var processor = function(timer) { | |
return new Promise(function(resolve, reject) { | |
setTimeout(resolve, timer * 1000); | |
}); | |
} | |
var serial_timeout = function(timer_arr) { | |
var co = require('co'); | |
co(function *() { | |
for (var i = 0; i < timer_arr.length; i++) { | |
yield processor(timer_arr[i]); | |
console.log("processing... [" + i + "]"); | |
} | |
console.log("finish!"); | |
}); | |
} | |
serial_timeout([1, 3, 5, 7, 9, 11, 13, 15]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment