Attach a callback to a hook.
420786
def add(self, name, func):
        '''  '''
        if name not in self.hooks:
            raise ValueError("Unknown hook name %s" % name)
        was_empty = self._empty()
        self.hooks[name].append(func)
        if self.app and was_empty and not self._empty(): self.app.reset()
971104
def post_run_hook(self, func, prefix=None):
        
        cf = self.capture(func, prefix=prefix)
        self.post_run_hooks.append(cf)
        return cf
493967
function call(handle) {
          handle.callback.apply(handle.context, args);
          called = true;
        }
312689
def on(hook_type, state_or_event_name = nil, async = nil, &callback)
      sync_exclusive do
        if state_or_event_name.nil?
          state_or_event_name = HookEvent.any_state_or_event(hook_type)
        end
        async = false if async.nil?
        ensure_valid_callback_name!(hook_type, state_or_event_name)
        callback.extend(Async) if async == :async
        hooks.register(hook_type, state_or_event_name, callback)
      end
    end
1078193
def wrap_callback(function):
        """"""

        @wraps(function)
        def wrapped(task):
            task._callback_result = function(task)
            return task._callback_result

        return wrapped
676124
def add_action_callback(self, *event):
        """"""
        if react_to_event(self.view, self.tree_view, event) and self.active_entry_widget is None:
            self.on_add(None)
            return True
494467
def add_callback(self, events, callback):
        """"""
        if self._poll is None:
            raise RuntimeError('poll instance is closed')
        if events & ~(READABLE|WRITABLE):
            raise ValueError('illegal event mask: {}'.format(events))
        if events & READABLE:
            self._readers += 1
        if events & WRITABLE:
            self._writers += 1
        handle = add_callback(self, callback, events)
        self._sync()
        return handle
50686
def trigger_hook(self, name, *args, **kwargs):
        """"""
        method = getattr(self, name, None)
        if is_callable(method):
            method(*args, **kwargs)
            
        try:
            children = self.children
        except AttributeError:
            return
        else:
            if children is not None:
                for child in children:
                    method = getattr(child, 'trigger_hook', None)
                    if is_callable(method):
                        method(name, *args, **kwargs)
                    else:
                        method = getattr(child, name, None)
                        if is_callable(method):
                            method(*args, **kwargs)
1326281
def _invoke_hook(hook_name, target):
    
    try:
        for value in getattr(target, hook_name):
            func, args, kwargs = value
            func(target, *args, **kwargs)
    except AttributeError:
        # no hook defined
        pass
    except (TypeError, ValueError):
        # hook not properly defined (might be a mock)
        pass
1141195
function addHook (hook) {
    /* Accepting a nodeback, promisify it; else, store as it */
    const pHook = (hook.length > 1) ? Promise.promisify(hook) : hook;
    G.hooks.push(pHook);
}
304084
def register_hook(self, hook_name, fn):
        """"""
        if hook_name not in self._hooks:
            self._hooks[hook_name] = fn
        else:
            raise Exception('%s hook already registered' % hook_name)
155727
def observe(self, key: str, callback: Callable[[Any, Any], None]):
        """"""
        if key not in self._callbacks:
            self._add_key(key)
        self._callbacks[key].append(callback)
355362
function(type, callback) {
        var list = this.__hooks[type] || [];
            list.push(callback);

        this.__hooks[type] = list;
    }
653738
protected function call_hook()
    {
        $args = func_get_args();
        $name = array_shift($args);

        if ($this->has_hook($name)) {
            $callback = $this->_hooks[$name];

            if ( ! is_callable($callback)) {
                return false;
            }

            if (is_php('5.4.0') and $callback instanceof Closure) {
                $callback->bindTo($this);
            }

            return call_user_func_array($callback, $args);
        }

        return false;
    }
1235717
function hook() {
      var comp = hook.proxy.apply(null, arguments);
      for(var i = 0;i < hooks.length;i++) {
        hooks[i].apply(comp, arguments);
      }
      return comp;
    }
1055540
def add_action_callback(self, key_value, modifier_mask, a_dict=False):
        """"""
        if react_to_event(self.view, self.tree_view, event=(key_value, modifier_mask)) and self.active_entry_widget is None:
            self.on_add(None, a_dict)
            return True
139657
def hook_scope(self, name=""):
        """"""
        assert not self.revision
        self.cursor.execute(
            'insert into hooks (hook, date) values (?, ?)',
            (name or sys.argv[0],
             datetime.datetime.utcnow().isoformat()))
        self.revision = self.cursor.lastrowid
        try:
            yield self.revision
            self.revision = None
        except Exception:
            self.flush(False)
            self.revision = None
            raise
        else:
            self.flush()