Created
June 9, 2014 19:27
-
-
Save timruffles/49236e3099c7e01fb4e8 to your computer and use it in GitHub Desktop.
promise wrapper for node's less friendly APIs - net.connect etc
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
// e.g | |
// asyncObject(net.connect,{port: 8125}) | |
function asyncObject(constructor) { | |
var args = [].slice.call(arguments,1); | |
var obj = constructor.apply(null,args); | |
return new Promise(function(resolve,reject) { | |
obj.once("error",reject); | |
obj.once("connect",function() { | |
resolve(obj); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment