Skip to content

Commit ef76e8d

Browse files
committed
Add documentation about promises and hooks
1 parent 7f1c481 commit ef76e8d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

doc/module-development.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,20 @@ modules directly from the namespace::
108108
Module hooks
109109
------------
110110

111-
This is a list of module hooks, when they are called, and what arguments they
112-
receive.
111+
Hooks are called by the application in order to delegate work to registered
112+
modules. This is a list of module hooks, when they are called, and what
113+
arguments they receive.
114+
115+
It is possible to add your own hooks to your application by invoking the
116+
:func:`~annotator.App.prototype.runHook` method on the application instance.
117+
The return value is a :term:`Promise` that resolves to an ``Array`` of the
118+
results of the functions registered for that hook (the order of which is
119+
undefined).
120+
121+
Hook functions may return a value or a :term:`Promise`. The latter is sometimes
122+
useful for delaying actions. For example, you may wish to return a
123+
:term:`Promise` from the ``beforeAnnotationCreated`` hook when an asynchronous
124+
task must complete before the annotation data can be saved.
113125

114126

115127
.. function:: configure(registry)

0 commit comments

Comments
 (0)