Skip to content

Instantly share code, notes, and snippets.

@Marak
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save Marak/22c75eea663c16d195bb to your computer and use it in GitHub Desktop.
Save Marak/22c75eea663c16d195bb to your computer and use it in GitHub Desktop.
Merge multiple Hooks into a single Hook
var http = require('http');
module['exports'] = function recieveHttp (hook) {
var hook2 = hook.open('http://hook.io/Marak/echo?foo=bar');
var hook3 = hook.open('http://hook.io/Marak/echo');
var hooks = 2;
function complete() {
hooks--;
if (hooks === 0) {
hook.res.end('hook2 and hook3 have both ended');
}
}
hook2.on('data', function(chunk){
hook.debug('hook2 got data' + chunk.toString());
hook.res.write(chunk.toString());
});
hook3.on('data', function(chunk){
hook.debug('hook3 got data ' + chunk.toString());
hook.res.write(chunk.toString());
});
hook2.on('end', complete);
hook3.on('end', complete);
hook3.write('hello');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment