Skip to content

Instantly share code, notes, and snippets.

@grncdr
Forked from Marak/mergeHooks.js
Last active August 29, 2015 14:09
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 grncdr/693b79eb39272219195e to your computer and use it in GitHub Desktop.
Save grncdr/693b79eb39272219195e 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