-
-
Save uupaa/1bed9793742bf5c2b3bd60e619df90de to your computer and use it in GitHub Desktop.
convert Array#forEach(async/await) to await Promise.all(Arraymap(async/await))
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
/* | |
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