Created
June 7, 2023 04:35
-
-
Save xwlee/9bf3fdcd6283787e5b3cf0285b0f9e03 to your computer and use it in GitHub Desktop.
mapAsync.ts
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
const mapAsync = <T, R>(arr: T[], fn: (x: T) => Promise<R>) => | |
Promise.all(arr.map(fn)); | |
(async () => { | |
console.log("START MAP"); | |
const mapped = await mapAsync([1, 2, 3, 4], async (n) => { | |
const x = await fakeAPI(n * 1000, n); | |
return x * 10; | |
}); | |
useResult(mapped); | |
console.log("END MAP"); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment