【发布时间】:2018-04-22 12:34:53
【问题描述】:
使用 Promise 时,它们会自动运行而不被调用。我按照 MDN Docs 进行设置,它们在声明时运行,没有提示。
var progressPromise = new Promise(function(resolve, reject) {
// Query the DB to receive the ToDo tasks
// inProgress is the tableID
getTasks(inProgress, function(tasks) {
// Check that the list is returned.
console.log("Shouldn't Run Automatically");
if (tasks) {
console.log("This Too Runs Automatically");
resolve(tasks);
} else {
reject("There was a failure, the data was not received");
}
});
});
<p>Console Output</p>
<p> Shouldn't Run Automatically </p>
<p> This too runs automatically </p>
我检查了剩余的代码,只有当我使用node index.js 启动应用程序时才会触发承诺
这是设计使然,还是我的实现有误?如果它是设计使然,那么如果您可以将我链接到文档,那就太好了,因为我在上面找不到任何东西。
谢谢!
【问题讨论】:
标签: javascript node.js promise es6-promise