gpt4 book ai didi

javascript - promise 返回 promise ?

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

我正在尝试创建以下 promise 语法:

我想在 post 函数之后调用辅助 then,我该怎么做?

randomBytes.then(function() {
return requestPromise.post(....);
}).then(function() {
// I want this part to be called after the POST
});

最佳答案

事实上这已经有效(正如评论所说 - 假设 .post 返回一个 promise )几乎是 then 的要点 - 它允许你等待东西.

如果您从 then 返回一个 promise,链将假定其状态,因此完成后只会调用以下段 .

randomBytes.then(function() {
return requestPromise.post(....);
}).then(function() {
// WILL ALWAYS BE CALLED AFTER THE POST
});

关于javascript - promise 返回 promise ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28276454/

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