我有3种异步方法和一种普通方法。如何依次运行这些方法?
async function Method1(obj) {
let url = 'https://www.googleapis.com/';
let obj = await (await fetch(url)).json();
console.log('seq 1');
}
async function Method2(obj) {
let url = 'https://www.googleapis.com/';
let obj = await (await fetch(url)).json();
console.log('seq 2');
}
async function Method3(obj) {
let url = 'https://www.googleapis.com/';
let obj = await (await fetch(url)).json();
console.log('seq 3');
}
function Method4 ()
{
//Some Non-Async Code
console.log('seq 4');
}
它应该给我连续的结果
seq 1
seq 2
seq 3
seq 4
实现此目的的正确方法是什么?
Just wrap it in another
async
function and useawait
to call these otherasync
functions.使用匿名包装器的示例: