
1 w292614191 OP |
2 timethinker 2022-12-06 14:44:56 +08:00 Promise 构造函数传入的 executor 函数会被立即执行。 |
3 pixcai 2022-12-06 14:47:28 +08:00 2 楼说的对 |
4 churchill 2022-12-06 14:47:40 +08:00 谁的理论呀? ECMAScript 的理论是立即执行 https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-promise-executor |
5 johnli 2022-12-06 14:52:14 +08:00 2 楼说的对,所以依赖的顺序是 resolve 的结果,不是中间过程 |
6 w292614191 OP @timethinker #2 也就是在需要的时候构建,而不是提交构建放哪里? |
7 w292614191 OP @timethinker #2 而不是提前构建好。 |
8 w292614191 OP |
9 w292614191 OP 如果是“立即执行” ,Promise.all 的意义是啥?结果都产生了。 |
10 timethinker 2022-12-06 15:26:20 +08:00 Promise != Lazy ,你需要的更像是 Lazy |
11 timethinker 2022-12-06 15:31:31 +08:00 刚 Google 到的一篇文章: https://tusharf5.com/posts/js-promises-eager-not-lazy/ |
12 w292614191 OP @timethinker #11 学习了,非常感谢,我现在理解了。 |
13 jadehare 2022-12-06 15:50:55 +08:00 @w292614191 #9 let getSys = function(resolve){ console.log("111") resolve(); } ruleArr.push(getSys); Promise.all(ruleArr.map(a=>new Promise(a))); |
14 Yeen 2022-12-06 21:14:25 +08:00 你传给 promise 的异步回调本身并不能保证同步顺序。 这个问题简化一下更好理解。你构造两个 promise ,都是 http 请求。你并不能保证哪个请求先返回。 如果需要同步,要么在 then 串行起来;要么 await 同步。 |
15 Yeen 2022-12-06 21:19:26 +08:00 @w292614191 立即执行不等于立即有结果。比如网络请求 |
16 okakuyang 2022-12-07 00:22:37 +08:00 可以在 for of 里用 awit 顺序执行 |
17 ZoeeoZ 2022-12-07 11:05:46 +08:00 promise.all 我遇到过最迷幻的一次问题是: 里边的两个(校验表单的)函数调换一下顺序(比如 B,A)就永远走失败,但不调换(A,B)就正常,我调了 N 久才发现是这俩顺序的问题 |