Skip to content

Instantly share code, notes, and snippets.

@timruffles
Created June 9, 2014 19:27
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 timruffles/49236e3099c7e01fb4e8 to your computer and use it in GitHub Desktop.
Save timruffles/49236e3099c7e01fb4e8 to your computer and use it in GitHub Desktop.
promise wrapper for node's less friendly APIs - net.connect etc
// 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