Skip to content

Commit

Permalink
Update files after the review
Browse files Browse the repository at this point in the history
  • Loading branch information
xuniq committed Jul 28, 2022
1 parent 51251d6 commit 4758194
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
24 changes: 8 additions & 16 deletions doc/reference/reference_lua/box_events/system_events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ The events are available from the beginning as non-:ref:`MP_NIL <box_protocol-no
If a watcher subscribes to a system event before it has been broadcast,
it receives an empty table for the event value.

The event is generated when there is a change in any of the values listed in the event.
For example, see the parameters in the ``box.id`` event below -- ``id``, ``instance_uuid``, and ``replicaset_uuid``.
Suppose the ``ìd`` value (``box.info.id``) has changed.
This triggers the ``box.info`` event, which states that the value of ``box.info.id`` has changed,
while ``box.info.uuid`` and ``box.info.cluster.uuid`` remain the same.

box.id
~~~~~~

Expand Down Expand Up @@ -100,25 +106,11 @@ Usage example
.. code-block:: lua
local conn = net.box.connect(URI)
local log = require('log')
-- Subscribe to updates of key 'box.id'
local w = conn:watch('box.id', function(key, value)
assert(key == 'box.id')
-- do something with value
end)
-- or subscribe to updates of key 'box.status'
w = conn:watch('box.status', function(key, value)
assert(key == 'box.status')
-- do something with value
end)
-- or subscribe to updates of key 'box.election'
w = conn:watch('box.election', function(key, value)
assert(key == 'box.election')
-- do something with value
end)
-- or subscribe to updates of key 'box.schema'
w = conn:watch('box.schema', function(key, value)
assert(key == 'box.schema')
-- do something with value
log.info("The box.id value is '%s'", value)
end)
If you want to unregister the watcher when it's no longer needed, use the following command:
Expand Down
20 changes: 19 additions & 1 deletion doc/reference/reference_lua/box_events/watch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ box.watch()
In this case, the watcher remains registered.
It is okay to discard the result of ``watch`` function if the watcher will never be unregistered.

**Example:**
**Examples:**

.. code-block:: lua
Expand All @@ -33,6 +33,24 @@ box.watch()
-- do something with value
end)
Server:

.. code-block:: lua
-- Broadcast value 42 for the 'foo' key.
box.broadcast('foo', 42)
Client:

.. code-block:: lua
local conn = net.box.connect(URI)
-- Subscribe to updates of the 'foo' key.
local w = conn:watch('foo', function(key, value)
assert(key == 'foo')
-- do something with value
end)
If you don't need the watcher anymore, you can unregister it using the command below:

.. code-block:: lua
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/reference_lua/net_box.rst
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ Below is a list of all ``net.box`` functions.

.. code-block:: lua
-- Broadcast value 123 for the key 'foo'.
-- Broadcast value 123 for the 'foo' key.
box.broadcast('foo', 123)
Client:
Expand Down

0 comments on commit 4758194

Please sign in to comment.