Methods
(static) spawn(optionsopt, callback) → {Object}
Creates a new instance of UniversalVM.
This is merely an alias of the construction creation without needing to
write the new
keyword and creating explicit connection.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
UniversalVM.connectOptions |
<optional> |
Options to configure the UVM |
callback |
function | Callback function |
Returns:
UVM event emitter instance
- Type
- Object
Example
const uvm = require('uvm');
uvm.spawn({
bootCode: `
bridge.on('loopback', function (data) {
bridge.dispatch('loopback', 'pong');
});
`
}, (err, context) => {
context.on('loopback', function (data) {
console.log(data); // pong
});
context.dispatch('loopback', 'ping');
});
connect(optionsopt, callback)
Establish connection with the communication bridge.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
UniversalVM.connectOptions |
<optional> |
Options to configure the UVM |
callback |
function | Callback function |
disconnect()
Disconnect the bridge and release memory.
dispatch()
Emit an event on the other end of bridge.
The parameters are same as emit
function of the event emitter.
Type Definitions
connectOptions
Configuration options for UniversalVM connection.
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
bootCode |
Boolean |
<optional> |
Code to be executed inside a VM on boot |
|
_sandbox |
Boolean |
<optional> |
Custom sandbox instance |
|
debug |
Boolean |
<optional> |
Inject global console object in Node.js VM |
|
bootTimeout |
Boolean |
<optional> |
30 * 1000 | The time (in milliseconds) to wait for UVM boot to finish |
dispatchTimeout |
Boolean |
<optional> |
30 * 1000 | The time (in milliseconds) to wait for UVM dispatch process to finish |