javascript同步函数

时间:2017-08-17 05:17:26

标签: javascript mongodb phantomjs

我在javascript代码中有三个函数,一个连接到我的mongo数据库,另一个创建子进程并将数据库的值传递给phantamjs子进程,第三个从phantomjs获取数据并处理它。

我想让这些功能同步。这有什么具体的方法吗?

这就是我想要做的事情

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()
}

我希望同步调用这些函数.. connectdb()然后create_child()然后是process_data()

2 个答案:

答案 0 :(得分:0)

您可以使用javascript generators同步执行您的功能。

答案 1 :(得分:-1)

您可以使用Promise执行此操作。

相关问题