sergeyksv/tinyhook — pull request #8 by xmilliard (2012-06-27 13:24:37+00:00)
Title: hook shutdown

Hello, in order to have a nice shutdown for hooks, we need to stop garbage collector timer.

Here is an example (doesn't work before patch, ok after).

~~~{ .javascript}
var Hook = require('tinyhook').Hook;

hook1 = new Hook({name:'hook1'});
hook1.on('*::alive', function(data) {
console.log('hook1 receives alive');
});
hook1.start();

hook2 = new Hook({name:'hook2'});
hook2.start();

hook2.on('hook::ready', function() {
console.log('hook2 ready');
hook2.emit('alive', 'toto');
});

setTimeout(function() {
hook2.stop(function() {
console.log('hook2 stopped');
});
}, 1000);
setTimeout(function() {
hook1.stop(function(){
console.log('hook1 stoppped');
});
}, 2000);

~~~