Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* bluebird 顺序批量下载
*/
const Promise = require("bluebird");
const cmd = require('node-cmd');
const cmdRuner = Promise.promisify(cmd.get, { multiArgs: true, context: cmd });
let arr = [];
const makePromise = function(i) {
return new Promise((resolve, reject) => {
console.log(`开始下载第${i}个视频`);
cmdRuner(`you-get https://cdn.xxxx.com/v/${i}.mp4`).then((res) => {
console.log(`${i}个视频下载完毕`);
resolve(res);
}).catch((e) => {
reject(e);
})
})
}
for (let i = 1; i < 3; i++) {
arr.push(i);
}
Promise.mapSeries(arr, (item, index) => makePromise(item)).then(res => {
console.log('->', 'done');
}).catch((e) => {
console.log('error->', e)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.