Created
August 27, 2015 19:20
-
-
Save Jonahss/3c75a9165ebfaad9c96b to your computer and use it in GitHub Desktop.
promisify event listeners
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
'use strict' | |
let fs = require('fs'); | |
let B = require('bluebird'); | |
let readStream = fs.createReadStream(__filename) | |
readStream.on('close', function() { | |
console.log('regular close cb called') | |
}) | |
let on = B.promisify(readStream.on, readStream); // the second argument is important, is specifies the 'this' context to bind the function too | |
on('close').then(function() { | |
console.log('promisify close promise resolved') | |
}) | |
readStream.pipe(fs.createWriteStream('/dev/null')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment