Created
January 5, 2023 15:36
-
-
Save maxsimych/1a1bc00df288dab05161237a180854f2 to your computer and use it in GitHub Desktop.
Example of JavaScript promise chain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function createPromiseChain(arrayForAsyncTasks) { | |
| let promiseChain = Promise.resolve(); | |
| for (let i = 0; i < arrayForAsyncTasks.length; i++) { | |
| const dataForAsyncTask = arrayForAsyncTasks[i]; | |
| promiseChain = promiseChain.then(() => { | |
| return doAsyncTask(dataForAsyncTask); | |
| }); | |
| } | |
| return promiseChain; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment