Skip to content

Instantly share code, notes, and snippets.

@yokotak0527
Last active August 28, 2019 15:46
Show Gist options
  • Save yokotak0527/d0ed55429df8589acbeb820f09ae27d9 to your computer and use it in GitHub Desktop.
Save yokotak0527/d0ed55429df8589acbeb820f09ae27d9 to your computer and use it in GitHub Desktop.
並列処理を直列処理にする案
function async1 () {
return new Promise(resolve => {
setTimeout(() => {
resolve('async1 done')
}, 3000)
})
}
function async2 () {
return new Promise(resolve => {
setTimeout(() => {
resolve('async2 done')
}, 1000)
})
}
(async list => {
for (let f of list) console.log(await f())
})([async1, async2])
@yokotak0527
Copy link
Author

async 使ってるので、この処理自体がPromiseを返してしまう。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment