我有一个简单的演示来理解 Promise 概念,但它没有按预期工作,请参阅我尝试过的代码。
module.exports = async function (context, iotHubMessage) {
context.log('START');
var promise1 = new Promise(function (resolve, reject) {
setTimeout(function () {
resolve('foo');
}, 1000);
});
context.log(promise1);
promise1.then(function (resolve) {
context.log(resolve);
// expected output: "foo"
});
};
我得到这个输出
2019-01-24T12:58:38.695 [Information] START
2019-01-24T12:58:38.695 [Information] Promise { <pending> }
2019-01-24T12:58:38.696 [Information] Executed
为什么没有得到foo
输出日志请帮助我谢谢!