You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
box.watch(key, func) registers a watcher for the given key and returns
a watcher handle, which can be used to unregister the watcher (by
calling the unregister method). A key is an arbitrary string. It's
possible to register more than one watcher for the same key. Note,
garbage collection of a watcher handle doesnt result in unregistering
the watcher so it's okay to discard the result of box.watch if the
watcher is never going to be unregistered.
box.broadcast(key, value) updates the value of the given key and
signals all watchers registered for it.
A watcher callback is first invoked unconditionally after the watcher
registration. Subsequent invocations are triggered by box.broadcast()
called on the local host. A watcher callback is passed the name of the
key the watcher was subscribed to and the current key value. A watcher
callback is always executed in a new fiber so it's okay to yield inside
it. A watcher callback never runs in parallel with itself: if the key
to which a watcher is subscribed is updated while the watcher callback
is running, the callback will be invoked again with the new value as
soon as it returns.
box.watch and box.broadcast may be used before box.cfg.
Example usage:
-- Broadcast value 123 for key 'foo'.box.broadcast('foo', 123)
-- Subscribe to updates of key 'foo'.w=box.watch('foo', function(key, value)
assert(key=='foo')
-- do something with valueend)
-- Unregister the watcher when it's no longer needed.w:unregister()
xuniq
added
feature
A new functionality
reference
[location] Tarantool manual, Reference part
server
[area] Task relates to Tarantool's server (core) functionality
labels
Nov 18, 2021
xuniq
changed the title
Document box.watch and box.broadcast
[5pt?] Document box.watch and box.broadcast
Dec 3, 2021
Fixes#2551Fixes#2409Fixes#2407
* Add new functions to module box
* Update watch and broadcast methods
* Add System events section
* Add glossary
* Proofread text and add links
Written by Kseniia Antonova
Reviewed by Vladimir Davydov and Dmitry Oboukhov
Proofread by Patience Daur
Co-authored-by: Kseniia Antonova <xuniq.is.here@gmail.com>
Co-authored-by: Patience Daur <patiencedaur@gmail.com>
Document functions
box.watch
andbox.broadcast
Product: Tarantool
Root document: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box/
SME: @ locker
Peer reviewer:
Details
box.watch(key, func)
registers a watcher for the given key and returnsa watcher handle, which can be used to unregister the watcher (by
calling the
unregister
method). A key is an arbitrary string. It'spossible to register more than one watcher for the same key. Note,
garbage collection of a watcher handle doesnt result in unregistering
the watcher so it's okay to discard the result of
box.watch
if thewatcher is never going to be unregistered.
box.broadcast(key, value)
updates the value of the given key andsignals all watchers registered for it.
A watcher callback is first invoked unconditionally after the watcher
registration. Subsequent invocations are triggered by
box.broadcast()
called on the local host. A watcher callback is passed the name of the
key the watcher was subscribed to and the current key value. A watcher
callback is always executed in a new fiber so it's okay to yield inside
it. A watcher callback never runs in parallel with itself: if the key
to which a watcher is subscribed is updated while the watcher callback
is running, the callback will be invoked again with the new value as
soon as it returns.
box.watch
andbox.broadcast
may be used beforebox.cfg
.Example usage:
Requested by @locker in tarantool/tarantool@11f2d99.
The text was updated successfully, but these errors were encountered: