Created
August 16, 2017 21:38
-
-
Save nmccready/7effebf38bb614e2a3e7c98ac183136b to your computer and use it in GitHub Desktop.
emitter extension
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
var Promise = require('bluebird'); | |
var EventEmitter = require('events'); | |
function toPromise(emitterLike) { | |
return new Promise(function(resolve, reject) { | |
emitterLike.once('finish', resolve); | |
emitterLike.once('end', resolve); | |
emitterLike.once('close', resolve); | |
return emitterLike.once('error', reject); | |
}); | |
}; | |
if (EventEmitter.prototype.toPromise == null) { | |
EventEmitter.prototype.toPromise = function() { | |
return toPromise(this); | |
}; | |
} else { | |
logger.warn("EventEmitter::toPromise already exist! We should change the prototype naming."); | |
} | |
module.exports = { | |
toPromise: toPromise | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment