Command: signal

Syntax

signal <name>, {,<text>}

or

signal <name> = <ident>

Description

Create or redefine a signal identifier.

A signal identifier(not to be confused with a Unix low-level inter-process signal) provides a means of relaying events between objects.

Once a signal has been created, an object (i.e. an identifier) can raise the signal, supplying an arbitrary parameter, and this in turn will invoke callbacks on all objects who have registered themselves as listeners for this signal.

Parameters

Switches

None

Notes

Signals can only have global or application scope. If a declarative atable prefix is omitted then global is assumed.

Arrays of signals are permitted.

Example

Create a signal to be raised when database activity has been detected:

signal dbsig,'Database change'

Register 2 other objects (obj1 and obj2) as listeners.

dbsig.add_listener(obj1,db_activity)
dbsig.add_listener(obj2,db_changed)

Each listener has a callback, invoked when the signal gets raised. As in this example, different objects can have different callback names, but an object can only register itself once for a particular signal.

The signal gets raised by another object, in our case a database (mydb):

dbsig.raise(mydb,'insert')

In this instance we have passed a string as client data telling the listener that the signal is being raised because of an 'insert' event.

The signal mechanism will then invoke the following callbacks automatically as a result of the signal raise:

obj1.db_activity(dbsig,mydb,'insert')
obj2.db_changed(dbsig,mydb,'insert')

Note that the signal, the raiser and the client data are all passed to the callbacks as parameters.

See Also

Structures:

signal