watcher

Last updated 8 months ago

This extension provides support for setting up 'event watchers'.

For example, if you want to allow interested parties to watch for 'update' events, you might have something like this:

local thing = {}
thing.watchers = watcher.new('update')
thing.watch(events)
return thing.watchers:watch(events)
end
thing.update(value)
thing.value = value
thing.watchers:notify('update', value)
end

Then, your other code could get notifications like so:

thing.watch({
update = function(value) print "New value is "..value end
})

Then, whenever thing.update(xxx) is called, the watcher will output "New value is xxx".

API Overview

  • Functions - API calls offered directly by the extension

  • Methods - API calls which can only be made on an object returned by a constructor

API Documentation

Functions

new

Signature

cp.watcher.new(...) -> watcher

Type

Function

Description

Constructs a new watcher instance.

Parameters

Returns

Methods

events

Signature

cp.watcher:events()

Type

Method

Description

Returns a list of the event names supported by this watcher.

Parameters

Returns

getCount

Signature

cp.watcher:getCount()

Type

Method

Description

Returns the number of watchers currently registered.

Parameters

Returns

notify

Signature

cp.watcher:notify(type, ...) -> nil

Type

Method

Description

Notifies watchers of the specified event type.

Parameters

Returns

unwatch

Signature

cp.watcher:unwatch(id) -> boolean

Type

Method

Description

Removes the watchers which were added with the specified ID.

Parameters

Returns

watch

Signature

cp.watcher:watch(events) -> id

Type

Method

Description

Adds a watcher for the specified events.

Parameters

Returns