Skip to content

Instantly share code, notes, and snippets.

@ricokahler
Created February 7, 2018 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricokahler/969e9021c28fc862fd2532f96b02ffa0 to your computer and use it in GitHub Desktop.
Save ricokahler/969e9021c28fc862fd2532f96b02ffa0 to your computer and use it in GitHub Desktop.
map promises
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);
});
*/
@digia
Copy link

digia commented May 10, 2018

await Create.reduce(async (accum, data) => { const created = await creator(data); return [...accum, created]; }, []);

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