Promise in Google Apps Script
11538 ワード
summary
- logged as if await considered.
- execution time can't be shortend(duration counts evaluated as if ran synchronously).
await
const pt = async () => {
const p1 = new Promise((resolve, reject) => {
Utilities.sleep(2000);
resolve("one");
});
const p2 = new Promise((resolve, reject) => {
Utilities.sleep(5000);
resolve("two");
});
const t1 = new Date();
console.log(">");
await Promise.all([p1, p2]).then(results => {
console.log(results);
}).catch(reject => {
console.log(reject);
});
console.log("<");
console.log((new Date()) - t1);
}
Head pt エディタ 2020/11/22 22:49:32 7.399 秒
完了
2020/11/22 22:49:39 デバッグ >
2020/11/22 22:49:39 デバッグ [ 'one', 'two' ]
2020/11/22 22:49:39 デバッグ <
2020/11/22 22:49:39 デバッグ 23
no await
const pt = async () => {
const p1 = new Promise((resolve, reject) => {
Utilities.sleep(2000);
resolve("one");
});
const p2 = new Promise((resolve, reject) => {
Utilities.sleep(5000);
resolve("two");
});
const t1 = new Date();
console.log(">");
await Promise.all([p1, p2]).then(results => {
console.log(results);
}).catch(reject => {
console.log(reject);
});
console.log("<");
console.log((new Date()) - t1);
}
Head pt エディタ 2020/11/22 22:47:24 7.37 秒
完了
2020/11/22 22:47:31 デバッグ >
2020/11/22 22:47:31 デバッグ <
2020/11/22 22:47:31 デバッグ 6
2020/11/22 22:47:31 デバッグ [ 'one', 'two' ]
Author And Source
この問題について(Promise in Google Apps Script), 我々は、より多くの情報をここで見つけました https://zenn.dev/ulpianus/articles/ee6b2fcb979e33e088a8著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Collection and Share based on the CC protocol