Sharing data in Javascript
m |
|||
(One intermediate revision by one user not shown) | |||
Line 17: | Line 17: | ||
The Engine.shared object allows access to the [http://yate.null.ro/docs/api/TelEngine__SharedVars.html shared variables] held by the [http://yate.null.ro/docs/api/TelEngine__Engine.html Yate Engine]. | The Engine.shared object allows access to the [http://yate.null.ro/docs/api/TelEngine__SharedVars.html shared variables] held by the [http://yate.null.ro/docs/api/TelEngine__Engine.html Yate Engine]. | ||
This object allows performing simple set and retrieve operations and also atomic counter increments and decrements. | This object allows performing simple set and retrieve operations and also atomic counter increments and decrements. | ||
+ | |||
'''See also''' | '''See also''' | ||
Line 22: | Line 23: | ||
* [[Messages]] | * [[Messages]] | ||
* [[Javascript]] | * [[Javascript]] | ||
+ | |||
+ | [[Category:Javascript]] [[Category:Programmers]] |
Latest revision as of 15:33, 31 October 2013
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.
[edit] 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.
[edit]
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