new Worker()
worker.js, line 17
Create an instance
Example
Simple worker that prepends "echo: " to whatever it is sent and then sends it back to the manager
const {
Worker
} = require('fabam');
const worker = new Worker();
worker.on('echo', (what, callback)=>{
callback(`echo: ${what}`);
});
worker.ready();
Methods
-
emit(event, data)
worker.js, line 32 -
Send a message back to the manager
Name Type Description event
string Name of the event to send back
data
any What data to send back
-
on(event, handler)
worker.js, line 48 -
Setup a listener for an event. Called every time the worker gets the event.
Name Type Description event
string What even to listen for
handler
function function(data, done) handler for the event
Name Type Description data
any Data to be processed
done
function Function to return results to the manager
-
once(event, handler)
worker.js, line 61 -
Setup a listener for an event. Called only once, then removed.
Name Type Description event
string What even to listen for
handler
function function(data) handler for the event
-
ready()
worker.js, line 38 -
Let the manager know we are ready for work