Skip to content

Commit

Permalink
Update files after review
Browse files Browse the repository at this point in the history
  • Loading branch information
xuniq committed Jul 27, 2022
1 parent cb2837b commit 51251d6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion doc/reference/reference_lua/box_events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Below is a list of all functions and members related to watchers or events.
* - :doc:`./box_events/broadcast`
- Update a state.

* - :ref:`˜Built-in events <system-events>`
* - :ref:`Built-in events <system-events>`
- Predefined events in Tarantool

.. toctree::
Expand Down
16 changes: 10 additions & 6 deletions doc/reference/reference_lua/box_events/system_events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,32 @@ Usage example

.. code-block:: lua
conn = net.box.connect(URI)
local conn = net.box.connect(URI)
-- Subscribe to updates of key 'box.id'
w = conn:watch('box.id', function(key, value)
local w = conn:watch('box.id', function(key, value)
assert(key == 'box.id')
-- do something with value
end)
-- or to updates of key 'box.status'
-- 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 to updates of key 'box.election'
-- 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 to updates of key 'box.schema'
-- or subscribe to updates of key 'box.schema'
w = conn:watch('box.schema', function(key, value)
assert(key == 'box.schema')
-- do something with value
end)
-- Unregister the watcher when it's no longer needed.
If you want to unregister the watcher when it's no longer needed, use the following command:

.. code-block:: lua
w:unregister()
10 changes: 7 additions & 3 deletions doc/reference/reference_lua/box_events/watch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ box.watch()

:return: a watcher handle. The handle consists of one method -- ``unregister()``, which unregisters the watcher.

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

.. note::

Expand All @@ -28,10 +28,14 @@ box.watch()
-- Broadcast value 123 for the 'foo' key.
box.broadcast('foo', 123)
-- Subscribe to updates of the 'foo' key.
w = box.watch('foo', function(key, value)
local w = box.watch('foo', function(key, value)
assert(key == 'foo')
-- do something with value
end)
-- Unregister the watcher when it is no longer needed.
If you don't need the watcher anymore, you can unregister it using the command below:

.. code-block:: lua
w:unregister()
10 changes: 7 additions & 3 deletions doc/reference/reference_lua/net_box.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. _net_box-module:
zc.. _net_box-module:

--------------------------------------------------------------------------------
Module net.box
Expand Down Expand Up @@ -545,7 +545,7 @@ Below is a list of all ``net.box`` functions.
:param function func: a callback to invoke when the key value is updated
:return: a watcher handle. The handle consists of one method -- ``unregister()``, which unregisters the watcher.

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

The method has the same syntax as the :doc:`box.watch() </reference/reference_lua/box_events/broadcast>`
function, which is used for subscribing to events locally.
Expand Down Expand Up @@ -583,7 +583,11 @@ Below is a list of all ``net.box`` functions.
assert(key == 'foo')
-- do something with value
end)
-- Unregister the watcher if it is no longer needed.
If you don't need the watcher anymore, you can unregister it using the command below:

.. code-block:: lua
w:unregister()
.. _conn-timeout:
Expand Down

0 comments on commit 51251d6

Please sign in to comment.