Skip to content

ngerritsen/pull-from-observable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

pull-from-observable

Allows you get events from an observable in a pull-based manner.

Observables are push based, they keep pushing events to you. If you need to do some async work before you can handle the next event, you are pretty much out of luck. There are some solutions to apply buffering, but in the end, the observable source controls the data flow.

Pull from observable buffers the incoming values for you, and allows you to run next() when you are ready to process the next value. If there are no values, they will be provided when available.

Installation

With npm:

npm install pull-from-observable

With yarn:

yarn add pull-from-observable

Usage

Example with Rx observables:

const Rx = require('rxjs')
const pull = require('pull-from-observable')

const observable = Rx.Observable.interval(100).take(5) // Push values every 100ms, 5 times

pull(observable, (next, value) => {
  setTimeout(() => { // Do some async work that takes longer than the interval
    console.log(value)
    next() // Ready to pull next value
  }, 200)
})

// Output:
//
// 0
// 1
// 2
// 3
// 4

About

Allows reading events from an observable in a pull-based manner.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published