fork download
  1. function FUNC1(cb){
  2. console.log("1");
  3. setTimeout(function(){console.log("2")}, 250);
  4. setTimeout(function() {
  5. console.log("3");
  6. cb();
  7. }, 500);
  8. }
  9.  
  10.  
  11. function FUNC2(cb){
  12. console.log("4");
  13. setTimeout(function(){console.log("5")},350);
  14. setTimeout(function(){
  15. console.log("6");
  16. cb();
  17. }, 600);
  18. }
  19.  
  20. queue = [];
  21. queue.push(FUNC1);
  22. queue.push(FUNC2);
  23.  
  24. (function processQueue(queue) {
  25. if (queue.length) {
  26. queue.shift(0)(processQueue.bind(null, queue));
  27. }
  28. }(queue));
Success #stdin #stdout 0.06s 10968KB
stdin
Standard input is empty
stdout
1
2
3
4
5
6