Skip to content

Instantly share code, notes, and snippets.

@uupaa
Created July 4, 2018 22:59
Show Gist options
  • Save uupaa/1bed9793742bf5c2b3bd60e619df90de to your computer and use it in GitHub Desktop.
Save uupaa/1bed9793742bf5c2b3bd60e619df90de to your computer and use it in GitHub Desktop.
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