Constructor
- moduleName
- Type:
string
The module to load in the worker process.
- options optional
- Type:
object
An object containing option properties to configure the worker. Available properties are as follows:
maxWorkers
: The maximum number of child processes to spawn. Defaults toos.cpus().length
.env
: An object containing environment variables to set for the child process.execArgv
: Command-line arguments to pass to thenode
worker processes.
Create a new Worker which executes the given module.
Parameters:
Example:
// my-worker.js
function onavailable(path) {
console.log(`Realm available at ${path}`);
}
function onchange(change) {
console.log(`Realm at ${change.path} changed`);
}
function ondelete(path) {
console.log(`Realm at ${path} deleted`);
}
module.exports = {onchange, oncavailable, ondelete};
// server script
Realm.App.Sync.addListener(realmServerURL, adminUser, '.*', new Realm.Worker('my-worker'));