相关疑难解决方法(0)

等待Promise.all()和多个等待之间的任何区别?

之间有什么区别:

const [result1, result2] = await Promise.all([task1(), task2()]);
Run Code Online (Sandbox Code Playgroud)

const t1 = task1();
const t2 = task2();

const result1 = await t1;
const result2 = await t2;
Run Code Online (Sandbox Code Playgroud)

const [t1, t2] = [task1(), task2()];
const [result1, result2] = [await t1, await t2];
Run Code Online (Sandbox Code Playgroud)

javascript async-await

127
推荐指数
4
解决办法
7万
查看次数

等待多个并发等待操作

如何更改以下代码,以便触发异步操作并同时运行?

const value1 = await getValue1Async();
const value2 = await getValue2Async();
// use both values
Run Code Online (Sandbox Code Playgroud)

我需要做这样的事情吗?

const p1 = getValue1Async();
const p2 = getValue2Async();
const value1 = await p1;
const value2 = await p2;
// use both values
Run Code Online (Sandbox Code Playgroud)

javascript promise async-await es2017

31
推荐指数
2
解决办法
3820
查看次数

标签 统计

async-await ×2

javascript ×2

es2017 ×1

promise ×1