This is because you are returning an array of pending promises. If you want to fulfill these promises, you can use Promise.all. And if you want the result, you must await the resolution of Promise.all. Or you can also use .then.
Promise.all
await
.then
function sleep(seconds: number) { return new Promise(function(resolve) { setTimeout(resolve, 1000 * seconds); }); } function increment(input: number) { return input + 1; } async function main() { const nums = await Promise.all([1, 2, 3, 4, 5].map(async (num) => { await sleep(1); return increment(num); })); console.log(nums); // [ 2, 3, 4, 5, 6 ] } main();
Some comments have been hidden by the post's author - find out more
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is because you are returning an array of pending promises. If you want to fulfill these promises, you can use
Promise.all
. And if you want the result, you mustawait
the resolution ofPromise.all
. Or you can also use.then
.