gpt4 book ai didi

node.js - 如何运行 promise

转载 作者:搜寻专家 更新时间:2023-10-31 22:31:27 25 4
gpt4 key购买 nike

我知道这不是很傻,但是如何开始一个 promise 链呢?例如,我有

var p = new Promise(function(resolve,reject) {
setTimeout(function() {
return resolve("Hi from promise after timeout");
},1000);
});

如何运行?应该是这样的,

when(p)
.then(function(msg) {
console.log(msg);
})
.catch(function(error) {
console.error(error);
});

但是 when 没有定义。

最佳答案

你只需要做:

p.then(function(msg) {
console.log(msg);
})
.catch(function(error) {
console.error(error);
});

关于node.js - 如何运行 promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37926949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com