/ collar.js

collar.js v0.4.0 release note

Version 0.4.0

  • add a new operator atom

signature:
atom(comment : string, isEndAtom : boolean = false) : Node

By default, signal propagates among nodes asynchronously. Each signal emitted by upstream node is scheduled to run in the future by the direct downstream nodes. Sometimes, you want a signal to be processed during a part of the flow without being interrupted by other nodes. You can use atom operator to achieve this.

// the nodes between atom(true) and atom(false) will be executed 
// without being interrupted by other nodes

upstream
  .atom(true) // start an atom pipeline
  // .atom() works the same as .atom(true)
  .do(signal => console.log("1"))
  .do(signal => console.log("2"))
  .do(signal => console.log("3"))
  .atom(false) // end the atom pipeline

upstream
  .do(signal => console.log("a"))
  .do(signal => console.log("b"))
  .do(signal => console.log("c"))

upstream.push(new Signal(1));


// output
1
2
3
a
b
c

// ----------------------
// without atom
// ----------------------
upstream
  .do(signal => console.log("1"))
  .do(signal => console.log("2"))
  .do(signal => console.log("3"))

upstream
  .do(signal => console.log("a"))
  .do(signal => console.log("b"))
  .do(signal => console.log("c"))

upstream.push(new Signal(1));

// possible output
1
a
2
b
3
c