Sharing data in Javascript

From Yate Documentation
Revision as of 15:33, 31 October 2013 by Monica (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Javascript language does not support concurrent execution and locking so direct data sharing between different script instances in not possible. This page describes other ways of transferring data between Javascript instances and also with other components.

Sending data by messages

A simple (but relatively slow) method of communication between script instances is the use of messages.

One instance of the script installs a message handler for a mutually agreed message. The other instance populates and then dispatches or enqueues the agreed message.

Note that both instances may install a handler for same message in which case a message parameter should be used to establish which script should answer. It is also possible that a message is handled by multiple scripts, for example to add their own ID to a list held in a message parameter.

If the message is enqueued the communication occurs only from sender to receiver (data / event push).

For a dispatched message one or more results may be returned in the message parameters (data query / pull). In this case care must be taken to avoid deadlocks caused by having two (or more) scripts waiting for data provided by the other in a circular manner.

Using shared Engine variables

The Engine.shared object allows access to the shared variables held by the Yate Engine. This object allows performing simple set and retrieve operations and also atomic counter increments and decrements.


See also

Personal tools
Namespaces

Variants
Actions
Preface
Configuration
Administrators
Developers