11.. _box-watchers :
22
3- --------------------------------------------------------------------------------
43Event watchers
5- --------------------------------------------------------------------------------
4+ ==============
65
7- The ``box `` module contains some functions related to event subscriptions, also known as watchers.
8- The subscriptions are used to inform a client about server-side events.
9- To read more about the built-in events in Tarantool,
10- check the :doc: `pub/sub </reference/reference_lua/box_events/pub-sub >` section.
6+ The ``box `` module contains some features related to event subscriptions, also known as :term: `watchers <watcher> `.
7+ The subscriptions are used to inform a client about server-side :term: `events <event> `.
8+ Each event subscription is defined by a certain key.
119
1210.. glossary ::
1311
14- Watcher
15- A watcher is a :doc: ` callback < /book/box/triggers >` that is invoked when a state change occurs.
16- To register a local watcher, use the `` box.watch() `` function .
17- To create a remote watcher, user the `` conn:watch() `` function.
18- Note that it is possible to register more than one watcher for the same key .
12+ Event
13+
14+ An event is a state change or a system update that triggers the action of other systems .
15+ To read more about the built-in events in Tarantool,
16+ check the :doc: ` system events < /reference/reference_lua/box_events/system_events >` section .
1917
2018 State
2119 A state is an internally stored key-value pair.
2220 The key is a string.
2321 The value is an arbitrary type that can be encoded as MsgPack.
2422 To update a state, use the ``box.broadcast() `` function.
2523
26- First, a watcher callback is invoked after the watcher registration.
24+ Watcher
25+ A watcher is a :doc: `callback </book/box/triggers >` that is invoked when a state change occurs.
26+ To register a local watcher, use the ``box.watch() `` function.
27+ To create a remote watcher, use the ``watch() `` function from the ``net.box `` module.
28+ Note that it is possible to register more than one watcher for the same key.
29+
30+ How the watcher works
31+ ---------------------
32+
33+ First, you register a watcher.
34+ After that, the watcher callback is invoked for the first time.
2735In this case, the callback is triggered whether or not the key has already been broadcast.
28- After that, :doc: `box.broadcast() </reference/reference_lua/box_watchers /broadcast >` called on the remote host
29- triggers all subsequent invocations .
36+ All subsequent invocations are triggered with the :doc: `box.broadcast() </reference/reference_lua/box_events /broadcast >`
37+ called on the remote host .
3038If a watcher is subscribed for a key that has not been broadcast yet, the callback is triggered only once,
3139after the registration of the watcher.
3240
33- A watcher callback is passed the name of the key for which it was registered and the current key data.
34- A watcher callback is always invoked in a new fiber. It means that is is okay to yield in it.
41+ The watcher callback takes two arguments.
42+ The first argument is a name of the key for which it was registered.
43+ The second one contains current key data.
44+ The callback is always invoked in a new fiber. It means that is is okay to yield in it.
3545A watcher callback is never executed in parallel with itself.
3646If the key is updated while the watcher callback is running, the callback will be invoked again with the new
3747value as soon as it returns.
3848
3949``box.watch `` and ``box.broadcast `` functions can be used before :doc: `box.cfg </reference/reference_lua/box_cfg >`.
4050
41- .. note ::
42-
43- Keep in mind that garbage collection of a watcher handle doesn't lead to the watcher's destruction.
44- In this case, the watcher remains registered.
45- It is okay to discard the result of ``watch `` function if the watcher will never be unregistered.
46-
4751Below is a list of all functions and members related to watchers or events.
4852
4953.. container :: table
@@ -58,21 +62,21 @@ Below is a list of all functions and members related to watchers or events.
5862 * - Name
5963 - Use
6064
61- * - :doc: `./box_watchers /watch `
65+ * - :doc: `./box_events /watch `
6266 - Create a local watcher.
6367
6468 * - :ref: `conn:watch() <conn-watch >`
6569 - Create a watcher for the remote host.
6670
67- * - :doc: `./box_watchers /broadcast `
71+ * - :doc: `./box_events /broadcast `
6872 - Update a state.
6973
70- * - :ref: `˜Built-in events <pubsub >`
71- - Pub/sub system and predefined events
74+ * - :ref: `˜Built-in events <system-events >`
75+ - Predefined events in Tarantool
7276
7377.. toctree ::
7478 :hidden:
7579
7680 box_events/watch
7781 box_events/broadcast
78- box_events/pub-sub
82+ box_events/system_events
0 commit comments