Skip to content

Instantly share code, notes, and snippets.

@nixon1333
Created February 2, 2018 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nixon1333/3e85924b1ee2f2f9c2f4ff713f8495e0 to your computer and use it in GitHub Desktop.
Save nixon1333/3e85924b1ee2f2f9c2f4ff713f8495e0 to your computer and use it in GitHub Desktop.
Make async function to sync function without npm fiber
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