Created
February 2, 2018 16:31
-
-
Save nixon1333/3e85924b1ee2f2f9c2f4ff713f8495e0 to your computer and use it in GitHub Desktop.
Make async function to sync function without npm fiber
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
var restunResult = aNormalSyncFunc(); | |
function aNormalSyncFunc() { | |
var deAsync = require('deasync'); | |
var taskDoneCount = 0; | |
//task 1 is happening | |
tasks1(param, function(res1){ | |
//do something with data | |
taskDoneCount++; | |
}); | |
//task 2 is happening | |
tasks2(param, function(res2){ | |
//do something with data | |
taskDoneCount++; | |
}); | |
//task 3 is happening | |
tasks3(param, function(res3){ | |
//do something with data | |
taskDoneCount++; | |
}); | |
//task 4 is happening | |
tasks4(param, function(res4){ | |
//do something with data | |
taskDoneCount++; | |
}); | |
//since total async task count is 4, while loop will wait till total 4 tasks done. | |
while(taskDoneCount <= 4) {deAsync.sleep(100);} | |
//return anything you want. do something.. because it will return after 4 tasks are completed. | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment