Skip to content

Instantly share code, notes, and snippets.

@uupaa uupaa/a.js
Created Jul 4, 2018

Embed
What would you like to do?
convert Array#forEach(async/await) to await Promise.all(Arraymap(async/await))
/*
json.forEach(async (raw) => {
const segment = new Segment(this._net);
await segment.init(raw);
this._hash[raw.id] = segment;
this._list.push(segment);
});
*/
await Promise.all( json.map(async (raw, index) => {
const segment = new Segment(this._net);
await segment.init(raw);
this._hash[raw.id] = segment;
this._list[index] = segment;
}) );
this._list.sort((a, b) => a.sid - b.sid);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.