Operator: map
The synchronous version of processor(). The processSync function does not take a callback function as argument, instead, its returned value is sent as the outgoing signal.
Signature
NS.map(comment : string, inputs : map, outputs : map, processSync : function) : Node
Arguments
Arguement | Type | Description |
---|---|---|
comment | string | optional, the comment of the processor |
inputs | map | optional, the input description |
outputs | map | optional, the output description |
processSync | function | optional, the process function, it throws Error or returns the new signal. If an error is threw, an error signal will be sent, otherwise, the returned signal will be emitted |
processSync function signature:
function processSync(signal : Signal) : Signal
If error is threw, an ERROR signal is sent to stream, otherwise the return signal is emitted
Return
Type | Description |
---|---|
Node | the processor node |
Create a sync processor
const ns = collar.ns('collarjs.demo.actuatorSync');
const input = ns.input('input');
input
.map("double the value", signal => {
return signal.set('value', signal.get('value') * 2);
})
.do(signal => console.log(s.get('value')));
input.push({value : 3}); // --> 6