Skip to content

Commit e727318

Browse files
committed
Resolved some comments
* Renamed pub/sub section to System events, removed paragraph about pub/sub, moved the event definition to Event watchers section * Removed code-block with empty table for the event values * Fixed some refs and links
1 parent 51bca07 commit e727318

File tree

5 files changed

+50
-73
lines changed

5 files changed

+50
-73
lines changed

doc/reference/reference_lua/box.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ with ``box``, with no arguments. The ``box`` module contains:
3434
box_space
3535
box_stat
3636
box_tuple
37-
box_watchers
3837

3938
box_txn_management
4039
box_sql
Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,53 @@
11
.. _box-watchers:
22

3-
--------------------------------------------------------------------------------
43
Event 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.
2735
In 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.
3038
If a watcher is subscribed for a key that has not been broadcast yet, the callback is triggered only once,
3139
after 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.
3545
A watcher callback is never executed in parallel with itself.
3646
If the key is updated while the watcher callback is running, the callback will be invoked again with the new
3747
value 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-
4751
Below 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

doc/reference/reference_lua/box_events/pub-sub.rst renamed to doc/reference/reference_lua/box_events/system_events.rst

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,7 @@
1-
.. _pubsub:
1+
.. _system-events:
22

3-
Pub/sub system and its events
4-
=============================
5-
6-
Overview
7-
--------
8-
9-
In Tarantool, :term:`pub/sub <publisher/subscriber>` is a :term:`notification` system for server-side
10-
:term:`events <event>`.
11-
12-
.. glossary::
13-
14-
event
15-
16-
An event is a state change or a system update update that triggers the action of other systems.
17-
18-
publisher/subscriber
19-
20-
A publish/subscribe pattern, also shortened as pub/sub, is a design pattern that consists of
21-
event producers (publishers), event consumers (subscribers or watchers), and event channel.
22-
Publishers communicate with watchers asynchronously by broadcasting events.
23-
They sent events to the pub/sub system.
24-
Then the system delivers received events to all the watchers that react to them.
25-
26-
notification
27-
28-
A notification is a message created by one side to inform about the occurrence of the event and describe
29-
it to other components.
30-
31-
The pub/sub pattern is associated with subscriptions.
32-
Each subscription is defined by the certain key.
33-
34-
Built-in events for pub/sub
35-
---------------------------
3+
System events
4+
=============
365

376
Predefined events have a special naming schema -- theirs names always start with the reserved ``box.`` prefix.
387
It means that you cannot create new events with it.
@@ -47,15 +16,8 @@ The system processes the following events:
4716
In response to each event, the server sends back certain ``IPROTO`` fields.
4817

4918
The events are available from the beginning as non-:ref:`MP_NIL <box_protocol-notation>`.
50-
If the events are broadcast before :doc:`box.cfg{} </reference/reference_lua/box_cfg>`,
51-
then the events values are empty:
52-
53-
.. code-block:: lua
54-
55-
box.id = {}
56-
box.schema = {}
57-
box.status = {}
58-
box.election = {}
19+
If a watcher subscribes to a system event before it has been broadcast,
20+
it receives an empty table for the event value.
5921

6022
box.id
6123
~~~~~~

doc/reference/reference_lua/box_events/watch.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ box.watch()
1515

1616
To read more about watchers, see the `Functions for watchers <box-watchers>` section.
1717

18+
.. note::
19+
20+
Keep in mind that garbage collection of a watcher handle doesn't lead to the watcher's destruction.
21+
In this case, the watcher remains registered.
22+
It is okay to discard the result of ``watch`` function if the watcher will never be unregistered.
23+
1824
**Example:**
1925

2026
.. code-block:: lua

doc/reference/reference_lua/net_box.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ Below is a list of all ``net.box`` functions.
547547

548548
To read more about watchers, see the `Functions for watchers <box-watchers>` section.
549549

550-
The method has the same syntax as the :doc:`box.watch() </reference/reference_lua/box_watchers/broadcast>`
550+
The method has the same syntax as the :doc:`box.watch() </reference/reference_lua/box_events/broadcast>`
551551
function, which is used for subscribing to events locally.
552552

553553
Watchers survive reconnection (see the ``reconnect_after`` connection :ref:`option <net_box-new>`).
@@ -558,6 +558,12 @@ Below is a list of all ``net.box`` functions.
558558
connection ``peer_protocol_features``.
559559
For details, check the :ref:`net.box features table <net_box-new>`.
560560

561+
.. note::
562+
563+
Keep in mind that garbage collection of a watcher handle doesn't lead to the watcher's destruction.
564+
In this case, the watcher remains registered.
565+
It is okay to discard the result of ``watch`` function if the watcher will never be unregistered.
566+
561567
**Example:**
562568

563569
Server:
@@ -575,7 +581,7 @@ Below is a list of all ``net.box`` functions.
575581
-- Subscribe to updates of the 'foo' key.
576582
w = conn:watch('foo', function(key, value)
577583
assert(key == 'foo')
578-
-- do something with value
584+
-- do something with value
579585
end)
580586
-- Unregister the watcher if it is no longer needed.
581587
w:unregister()

0 commit comments

Comments
 (0)