Created
August 21, 2016 11:11
-
-
Save mk-pmb/b1d95d2e8fb8d64024ae064e48513daf to your computer and use it in GitHub Desktop.
Promisify with control over selection, names and target.
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
/*jslint indent: 2, maxlen: 80, node: true */ | |
/* -*- tab-width: 2 -*- */ | |
'use strict'; | |
var EX = module.exports, Promise = require('bluebird'), origFs = require('fs'); | |
Object.keys(origFs).forEach(function customPromisify(key) { | |
var slot = origFs[key]; | |
if (slot instanceof Function) { | |
if (key.match(/Sync$/)) { return; } | |
if (key.match(/Stream$/)) { return; } | |
slot = Promise.promisify(slot.bind(origFs)); | |
} | |
EX[key] = slot; | |
}); | |
EX.readFile(module.filename, 'utf-8').then(function (data) { | |
console.dir(EX); | |
console.log(data.length); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment