-1

I have three functions in javascript code, one that connects to my mongo database, the other creates a child process and passes the value of database into the phantamjs child process, the third one gets the data from phantomjs and processes it.

I want to make these functions synchronous. is there any specific way of doing so?

This is what i want to do

function connectdb() {
                  //connects to mongodb and pushes the    
                  //value of emails from database to an array 
                  //also writes the emails into external .txt file
}
function create_child() {
                 //creates a child phantom process using external .js 
                 //phantom file 
                 //gets data from the child process
}
function process_data() { 
                //process the data received from create_child()
}

I want these functions to be called synchronously .. connectdb() then create_child() then process_data()

2 Answers2

0

you can use javascript generators to execute your functions synchronously.

Ashish Kumar
  • 212
  • 1
  • 7
-1

You can use Promise to do this.

atiq1589
  • 2,227
  • 1
  • 16
  • 24
  • yes. But in resolve he can do the next task and so on. He ask for to do the task one by one. – atiq1589 Aug 17 '17 at 05:20
  • no, he asked to turn asynchronous function (by way of time travel and magic beans) into synchronous function - you perpetuate the common misconception from years ago that promises can make asynchronous code synchronous – Jaromanda X Aug 17 '17 at 05:22
  • you can use javascript generators. – Ashish Kumar Aug 17 '17 at 05:24
  • No Promise can not make asynch function synchronous. its a better way of handling call back function. – atiq1589 Aug 17 '17 at 05:24