Last active
          September 19, 2017 16:23 
        
      - 
      
 - 
        
Save dimpiax/ef207b3eabaebf2540d1f9183f0374ed to your computer and use it in GitHub Desktop.  
Revisions
- 
        
dimpiax revised this gist
Sep 19, 2017 . 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 @@ -24,5 +24,5 @@ const result = await sync([1000, 500], async (value) => { return res }) console.log(result) // [2000, 1000] after 1500 ms */  - 
        
dimpiax revised this gist
Sep 19, 2017 . 1 changed file with 0 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,5 +1,3 @@ const next = async (it, callback) => { const { value, done } = it.next() if (done) return []  - 
        
dimpiax created this gist
Sep 19, 2017 .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,30 @@ /* @flow */ const next = async (it, callback) => { const { value, done } = it.next() if (done) return [] const result = await callback(value) const nextResult = await next(it, callback) return [result, ...nextResult] } const sync = async (value, callback) => { const it = value[Symbol.iterator]() const res = await next(it, callback) return res } export default { sync } // Usage: /** const result = await sync([1000, 500], async (value) => { const res = await new Promise((res) => { setTimeout(res, value, value * 2) }) return res }) console.log(result) // [2000, 500] after 1500 ms */