1 |
|
2 |
|
3 | function promisfy (mod, fn) {
|
4 | return function () {
|
5 | var args = Array.prototype.slice.call(arguments)
|
6 | return new Promise(function (resolve, reject) {
|
7 | args.push(function (err, res) {
|
8 | if (err) reject(err)
|
9 | else resolve(res)
|
10 | })
|
11 | mod[fn].apply(mod, args)
|
12 | })
|
13 | }
|
14 | }
|
15 |
|
16 | module.exports = promisfy(require('fs'), 'readFile')
|