var async = require('async');

var HOOKS = {};

exports.hook = function (key, func) {
	var hs = HOOKS[key];
	if (hs)
		hs.push(func);
	else
		HOOKS[key] = [func];
};

exports.trigger = function (key, arg, cb) {
	var hs = HOOKS[key] || [];
	async.forEachSeries(hs, function (hook, next) {
		hook(arg, next);
	}, function (err) {
		if (err)
			cb(err);
		else
			cb(null, arg);
	});
};

@@ -35,16 +35,33 @@
  HOOKS =
+ %7B%7D, SYNC_HOOKS =
  %7B%7D;%0A%0Aex
@@ -390,12 +390,276 @@
 g);%0A%09%7D);%0A%7D;%0A
+%0Aexports.hook_sync = function (key, func) %7B%0A%09var hs = SYNC_HOOKS%5Bkey%5D;%0A%09if (hs)%0A%09%09hs.push(func);%0A%09else%0A%09%09SYNC_HOOKS%5Bkey%5D = %5Bfunc%5D;%0A%7D;%0A%0Aexports.trigger_sync = function (key, arg) %7B%0A%09var hs = SYNC_HOOKS%5Bkey%5D %7C%7C %5B%5D;%0A%09hs.forEach(function (func) %7B%0A%09%09func(arg);%0A%09%7D);%0A%7D;%0A

Add synchronous hooks