All Projects â†’ staltz â†’ callbag-subject

staltz / callbag-subject

Licence: other
👜 A callbag listener sink which is also a listenable source

Programming Languages

javascript
184084 projects - #8 most used programming language

callbag-subject

A callbag listener sink which is also a listenable source, and maintains an internal list of listeners. Use this like you would use RxJS Subject.

npm install callbag-subject

example

First call makeSubject to create a subject which is then a normal callbag, so:

  • Call it with args (1, data) to send data into the subject
  • Call it with args (2, err) to send an error into the subject
  • Call it with args (2) to make the subject complete
const observe = require('callbag-observe');
const makeSubject = require('callbag-subject');

const subject = makeSubject();

setInterval(() => { subject(1, 'a'); }, 1000);

// First observer is added immediately
observe(x => console.log(x + 1))(subject);

// First observer is added after 2.5 seconds
setTimeout(() => {
  observe(x => console.log(x + 2))(subject);
}, 2500);

// a1
// a1
// a1
// a2
// a1
// a2
// ...
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].