Javascript等待函数的结束,包括node.js的异步MYSQL查询?
I'm having Javascript problem to wait a function done before the below line is called. The previous function is including the Javascript MYSQL Queries calls (one of the library of node.js). Then it will be looks like:
在调用下面一行之前,我有一个Javascript问题要等待一个函数完成。前面的函数包括Javascript MYSQL查询调用(node.js库中的一个)。然后会是:
function first() {
/**
* a lot processes to execute
* including Asynchronous processes
* like running Queries using Javascript MYSQL Library from node.js
*/
console.log("I am the first one!");
}
first();
console.log("I am the second one!");
Then when i execute this, it happening like:
当我执行它时,它就像:
I am second one!
I am first one!
How do i make them run by keeping the queue order?
如何通过保持队列顺序来运行它们?
NOTE: Now for everyone who confusing the question, please jump/follow my newly created question again:
Everyone please follow/jump into this new question: Node.js MYSQL to detect the INSERT/UPDATE completeness of a Query?
注意:现在,如果大家对这个问题感到困惑,请继续关注我的新问题:大家请继续关注这个新问题:Node。js MYSQL检测查询的插入/更新完整性?
3 个解决方案
#1
1
Pass a callback to the 2nd function to the call to the 1st function. At the end of the 1st function, invoke theh callback:
将回调传递给第二个函数,以调用第一个函数。在第一个函数的末尾,调用theh回调:
function one(parm, callback) {
// do something
callback();
}
function two() {
// do something else
}
one("my parm", two);
更多相关文章
- JavaScript数组操作函数方法详解
- JavaScript:使用函数参数检索javascript对象键
- 由浅到深的分析Javascript OO之写类方式之一:构造函数
- 如何在Node中创建可重用的函数而不编写样板代码
- d3。scaleSequential不是一个函数。
- 如何在SOF上的新帖子中没有像“Grippie”这样的'onclick'执行Jav
- 覆盖odoo 8中的JS函数
- JavaScript 函数柯里化(参考《JavaScript模式》)
- js中匿名函数的写法