Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Arvin iuunhao
Added: Jun 18, 2018 8:18 AM
Views: 10
Tags: js
链式调用异步函数
  1. const chainAsync = fns => { let curr = 0; const next = () => fns[curr++](next); next(); };
  2. /*
  3. chainAsync([
  4.   next => { console.log('0 seconds'); setTimeout(next, 1000); },
  5.   next => { console.log('1 second');  setTimeout(next, 1000); },
  6.   next => { console.log('2 seconds'); }
  7. ])
  8. */