gpt4 book ai didi

Javascript promise 结果范围

转载 作者:行者123 更新时间:2023-11-29 10:44:52 25 4
gpt4 key购买 nike

<分区>

我需要链接一些异步操作。我正在尝试编写使用 express 的 Parse.com 云代码。 (我认为 express 是 promise 支持的来源)。我明白为什么 promise 很有值(value),但我仍然不确定有几件事。首先是如何收集顺序操作的结果。下面的代码说明:

function doAsnychThingsInSequence(params) {
return doThing0(params).then(function(resultOfThing0) {
// thing1 depends on resultOfThing0
doThing1(resultOfThing0);
}).then(function(resultOfThing1) {
// here is where I am confused.
// thing2 depends on the results of thing0 and thing1
doThing2(resultOfThing0 /* out of scope?? */, resultOfThing1);
}, function(error) {
// handle error
});
}

thing1 完成后,我需要两个操作的结果。我想我可以在函数顶部分配一个变量并将其分配给第一个回调中的第一个结果,这是正确的方法吗?我想,我困惑的核心是问题二......

  return doThing0(params0).then(function(resultOfThing0) {
doThing1(resultOfThing0);
// what does return mean here? does what I return here relate to the
// parameters of the next function?
return "foo";
}).then(function(param) {
// what is in param? is it "foo"?
}, function(error) {
});

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