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 eventstring Name of the event to send back
dataany 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 eventstring What even to listen for
handlerfunction function(data, done) handler for the event
Name Type Description dataany Data to be processed
donefunction 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 eventstring What even to listen for
handlerfunction function(data) handler for the event
-
ready()
worker.js, line 38 -
Let the manager know we are ready for work