Created
February 7, 2018 17:02
-
-
Save ricokahler/969e9021c28fc862fd2532f96b02ffa0 to your computer and use it in GitHub Desktop.
map promises
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
export async function sequentially<T, R>(list: T[], asyncFunction: (t: T) => Promise<R>) { | |
const newList = [] as R[]; | |
for (const i of list) { | |
newList.push(await asyncFunction(i)); | |
} | |
return newList; | |
} | |
/* | |
// then use like so: | |
const sections = await sequentially(schedules, async schedule => { | |
const scheduleDetail = await fetchScheduleDetail(termCode, schedule.crn); | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
await Create.reduce(async (accum, data) => { const created = await creator(data); return [...accum, created]; }, []);