Skip to content

Instantly share code, notes, and snippets.

@Jonahss
Created August 27, 2015 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jonahss/3c75a9165ebfaad9c96b to your computer and use it in GitHub Desktop.
Save Jonahss/3c75a9165ebfaad9c96b to your computer and use it in GitHub Desktop.
promisify event listeners
'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