Yanor.net/
Wiki
Blog
GitHub
Sandbox
開始行:
* 02. Promise処理群のチェーン実行 [#xbde4db9]
** Promise処理群の作成 [#b0d1ddd6]
const task1 = () => {
return new Promise((resolve, reject) => {
// ここに処理1の処理を書く
resolve("Task 1 is done.");
});
};
const task2 = (message) => {
return new Promise((resolve, reject) => {
// ここに処理2の処理を書く
resolve(message + " Task 2 is done.");
});
};
const task3 = (message) => {
return new Promise((resolve, reject) => {
// ここに処理3の処理を書く
resolve(message + " Task 3 is done.");
});
};
** Promise処理群のチェーン実行(連結実行) [#b8a94101]
task1().then((result) => {
return task2(result);
}).then((result) => {
return task3(result);
}).then((result) => {
console.log(result + " Finished.");
});
** then()の返却値はPromiseオブジェクトでなくともよい [#x3...
task1().then((result) => {
return task2(result);
}).then((result) => {
return task3(result);
}).then((result) => {
return result + " Task A is done.";
}).then((result) => {
console.log(result + " Finished.");
});
- ここでは'''return result + " Task A is done.";'''はProm...
** 参考 [#af85f0cb]
https://ja.javascript.info/promise-chaining
終了行:
* 02. Promise処理群のチェーン実行 [#xbde4db9]
** Promise処理群の作成 [#b0d1ddd6]
const task1 = () => {
return new Promise((resolve, reject) => {
// ここに処理1の処理を書く
resolve("Task 1 is done.");
});
};
const task2 = (message) => {
return new Promise((resolve, reject) => {
// ここに処理2の処理を書く
resolve(message + " Task 2 is done.");
});
};
const task3 = (message) => {
return new Promise((resolve, reject) => {
// ここに処理3の処理を書く
resolve(message + " Task 3 is done.");
});
};
** Promise処理群のチェーン実行(連結実行) [#b8a94101]
task1().then((result) => {
return task2(result);
}).then((result) => {
return task3(result);
}).then((result) => {
console.log(result + " Finished.");
});
** then()の返却値はPromiseオブジェクトでなくともよい [#x3...
task1().then((result) => {
return task2(result);
}).then((result) => {
return task3(result);
}).then((result) => {
return result + " Task A is done.";
}).then((result) => {
console.log(result + " Finished.");
});
- ここでは'''return result + " Task A is done.";'''はProm...
** 参考 [#af85f0cb]
https://ja.javascript.info/promise-chaining
ページ名: