Created
March 24, 2021 12:12
-
-
Save gognjanovski/b3a59f933b110fb15664d82caedb6981 to your computer and use it in GitHub Desktop.
Asynchronous Map function extension for the Array interface
This file contains 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
interface Array<T> { | |
mapAsync<U>(callbackfn: (value: T, index: number, array: T[]) => Promise<U>, thisArg?: any): Promise<U[]>; | |
} | |
Array.prototype.mapAsync = function<U>(callbackfn: (value: any, index: number, array: any[]) => Promise<U>, thisArg?: any): Promise<U[]> { | |
var promises = this.map((value: any, index: number, array: any[]) => callbackfn(value, index, array)); | |
return Promise.all(promises); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment