1 2 3 4 5 | Promise.all([ fs.readFileAsync(path.join(__dirname, '1.txt'), 'utf-8'), fs.readFileAsync(path.join(__dirname, '2.txt'), 'utf-8'), fs.readFileAsync(path.join(__dirname, '3.txt'), 'utf-8') ]).then(results => console.log(results.join(', '))).catch(console.error); |
1 2 3 | Promise.map(['1.txt', '2.txt', '3.txt'], name => fs.readFileAsync(path.join(__dirname, name), 'utf-8') ).then(results => console.log(results.join(', '))).catch(console.error); |
1 2 3 4 5 | Promise.some([ fs.readFileAsync(path.join(__dirname, '1.txt'), 'utf-8'), fs.readFileAsync(path.join(__dirname, '2.txt'), 'utf-8'), fs.readFileAsync(path.join(__dirname, '3.txt'), 'utf-8') ], 2).then(results => console.log(results.join(', '))).catch(console.error); |
1 2 3 4 5 | Promise.filter([ fs.readFileAsync(path.join(__dirname, '1.txt'), 'utf-8'), fs.readFileAsync(path.join(__dirname, '2.txt'), 'utf-8'), fs.readFileAsync(path.join(__dirname, '3.txt'), 'utf-8') ], value => value.length > 1).then(results => console.log(results.join(', '))).catch(console.error); |
1 2 3 4 5 | Promise.reduce(['1.txt', '2.txt', '3.txt'], (total, name) => { return fs.readFileAsync(path.join(__dirname, name), 'utf-8').then(data => total + data.length); } , 0).then(result => console.log(`Total size: ${result}`)).catch(console.error); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |