Created
February 20, 2020 22:53
-
-
Save alfonmga/04950f2ed0c976680c887250443c6593 to your computer and use it in GitHub Desktop.
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
const _async = require('async'); | |
const _ = require('lodash'); | |
public doSomething = async(num) : Promise<any> => { | |
return num*num + 1; | |
} | |
public async getResults() { | |
let results = new Array<any>(); | |
let tasks = []; | |
try { | |
const list = [1,2,3,4,5,6,7,8,9,10]; | |
list.forEach((item) => { | |
tasks.push((callback) => { | |
this.doSomething(item.then( | |
(res) => { | |
results.push(res); | |
callback(null, res); | |
} | |
); | |
}) | |
}) | |
results = await new Promise((resolve) => { | |
_async.series(tasks, (err, res) => { | |
console.log(res); | |
if (err) { | |
results.push(err); | |
} | |
resolve(results); | |
}) | |
}); | |
} catch (err) { | |
results.push(err.message); | |
console.log(err); | |
} | |
return _.join(results, '\r\n'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment