Updated at July 17, 2026 02:08 PM
box.watch()
Subscribe to events broadcast by a local host.
Parameters:
-
key(string) — key name of the event to subscribe to -
func(function) — callback to invoke when the key value is updated
Returns
a watcher handle. The handle consists of one method –
unregister(), which unregisters the watcher.
To read more about watchers, see the Functions for watchers section.
Example:
-- Broadcast value 42 for the 'foo' key.box.broadcast('foo', 42)local log = require('log')-- Subscribe to updates of the 'foo' key.local w = box.watch('foo', function(key, value)assert(key == 'foo')log.info("The box.id value is '%d'", value)end)
If you don't need the watcher anymore, you can unregister it using the command below:
w:unregister()