Browse Source

Add synchronous hooks

tags/0.3.0
Lal'C Mellk Mal 7 years ago
parent
commit
5b1e1d4d78
1 changed files with 16 additions and 1 deletions
  1. +16
    -1
      hooks.js

+ 16
- 1
hooks.js View File

@@ -1,6 +1,6 @@
var async = require('async');

var HOOKS = {};
var HOOKS = {}, SYNC_HOOKS = {};

exports.hook = function (key, func) {
var hs = HOOKS[key];
@@ -21,3 +21,18 @@ exports.trigger = function (key, arg, cb) {
cb(null, arg);
});
};

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

exports.trigger_sync = function (key, arg) {
var hs = SYNC_HOOKS[key] || [];
hs.forEach(function (func) {
func(arg);
});
};

Loading…
Cancel
Save