Producer

Follow me on Twitter, happy to take your suggestions on topics or improvements /Chris

A producer have the task of producing the values emitted by an Observable

class Producer {
  constructor(){
    this.i = 0;
  }

  nextValue(){
    return this.i++;
  }
}

1
2
3
4
5
6
7
8
9
10

And to use it

let stream$ = Observable.create( (observer) => {
  const producer = new Producer();
  observer.next( producer.nextValue() )
  observer.next( producer.nextValue() )
})
1
2
3
4
5

In the Observable Anatomy chapter there is no Producer in the examples but most Observables that are created by a helper method will have an internal Producer producing values that the observer emits using the observer.next() method