Skip to content

Commit f396382

Browse files
authored
Add box.watch_once() (#4692)
Resolves #3510
1 parent 344c233 commit f396382

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

Diff for: doc/reference/reference_lua/box_events.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ Below is a list of all functions and pages related to watchers or events.
6464
* - Name
6565
- Use
6666

67-
* - :doc:`./box_events/watch`
67+
* - :ref:`box.watch() <box-watch>`
6868
- Create a local watcher.
6969

70+
* - :ref:`box.watch_once() <box-watch>`
71+
- Get the current key value.
72+
7073
* - :ref:`conn:watch() <conn-watch>`
7174
- Create a watcher for the remote host.
7275

@@ -80,5 +83,6 @@ Below is a list of all functions and pages related to watchers or events.
8083
:hidden:
8184

8285
box_events/watch
86+
box_events/watch_once
8387
box_events/broadcast
8488
box_events/system_events
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.. _box-watch_once:
2+
3+
box.watch_once()
4+
================
5+
6+
.. function:: box.watch_once(key, func)
7+
8+
Returns the current value of a given notification key.
9+
The function can be used as an alternative to :ref:`box.watch() <box-watch>`
10+
when the caller only needs the current value without subscribing to future changes.
11+
12+
:param string key: key name
13+
14+
:return: the key value
15+
16+
To read more about watchers, see the :ref:`box-watchers` section.
17+
18+
**Example:**
19+
20+
.. code-block:: lua
21+
22+
-- Broadcast value 42 for the 'foo' key.
23+
box.broadcast('foo', 42)
24+
25+
-- Get the value of this key
26+
tarantool> box.watch_once('foo')
27+
---
28+
- 42
29+
...
30+
31+
-- Non-existent keys' values are empty
32+
tarantool> box.watch_once('none')
33+
---
34+
...
35+
36+
37+

0 commit comments

Comments
 (0)