Skip to content

Instantly share code, notes, and snippets.

@asduser
Last active February 8, 2017 20:50
Show Gist options
  • Save asduser/4d63d5ce49416b30eb67b8bda2759104 to your computer and use it in GitHub Desktop.
Save asduser/4d63d5ce49416b30eb67b8bda2759104 to your computer and use it in GitHub Desktop.
Different operations with Promise via Typescript/Javascript.
let divide = (num: number, divider: number = 10) => {
return new Promise<any>((resolve, reject) => {
resolve(num / divider);
});
};
let collection: number[] = [30, 40, 50];
Promise.all(collection.map((n) => {
return divide(n);
})).then((res: number[]) => {
console.log(res); // output: [3, 4, 5]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment