Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const create = (request) => {
- return axios.post(link, body)
- // ^^^^^^--- return the chain
- .then((response) => Promise.all( // Wait for all promises we're about to create to resolve
- arr.map(obj => new Promise((resolve, reject) => { // What is `arr`?
- const file = fs.createWriteStream("./downloads/" + obj.name);
- https.get(obj.download_url, response => {
- let stream = response.pipe(file);
- stream
- .on("finish", () => {
- resolve(); // Resolve this download's result
- })
- .on(/*...presumably there's an error callbac*/, () => {
- reject();
- });
- });
- }));
- )
- .then(() => "Hi...."); // Final overall result
- // Don't catch errors, leave that to the caller
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement