Skip to content

Node class

Bo HOU edited this page Jul 8, 2016 · 9 revisions

Node class

Node

constructor(options, eventemitter)

Node constructor

-options: [any] - optional, any information you want to pass to node instance

-eventemitter: [Eventemitter] - optional, if you want the node to share a single event emitter use this parameter

Downstream API

push(signal)

Push a signal to the node.

-signal: [any] - the signal you want to push to node

-return: current node

onReceive(signal)

Handle received signal. Usually you don't need to override this method, the default implementation delegates the signal handling to three methods:

  • onSignal(signal) : handles the signal
  • onError(error) : handles the error
  • onEnd(signal) : handles the end

-signal: [any] - the signal to handle

-return: current node

send(signal)

Send a signal to the downstream nodes

-signal : the signal to send

-return: current node

onSignal(signal)

Handle received signal. Override this method to implement your operator

-signal: [any] - the signal to handle

-return: current node

onError(error)

Handle errors.

Note: the argument may not be an Error object. You can override throwError(error) method to throw any object to represent an error. This is very useful if your system have a customised error structure.

-error: [any] - the object that represented an error. See throwError(error)

-return: current node

onEnd(signal)

Handle END signal.

-signal: [any] - the END signal to handle

-return: current node

isErrorSignal(signal)

Check if an signal represents an error

-signal: [any] - the signal to check

-return: true if it represents an error otherwise false

isEndSignal(signal)

Check if an signal represents an END of stream

-signal: [any] - the signal to check

-return: true if it represents an END otherwise false

Upstream API

pull(cmd)

Request a signal to the upstream node by sending a command.

-cmd: [any] - the cmd in your request

-return: current node

onRequest(cmd)

Handle received request from downstream nodes. For most operator, you don't need to override this method, by default it calls request() method to pass the request to upstream.

-cmd: [any] - the command to handle

-return: current node

request(cmd)

Make a request to upstream

-cmd : the cmd to request

-return: current node

Clone this wiki locally