-
-
Save grncdr/693b79eb39272219195e to your computer and use it in GitHub Desktop.
Merge multiple Hooks into a single Hook
This file contains hidden or 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 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