pnpm
Version:
Fast, disk space efficient package manager
29 lines (25 loc) • 993 B
JavaScript
/** @license MIT License (c) copyright 2010-2016 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
import { withDefaultScheduler as run } from '../runSource'
import { tap } from './transform'
/**
* Observe all the event values in the stream in time order. The
* provided function `f` will be called for each event value
* @param {function(x:T):*} f function to call with each event value
* @param {Stream<T>} stream stream to observe
* @return {Promise} promise that fulfills after the stream ends without
* an error, or rejects if the stream ends with an error.
*/
export function observe (f, stream) {
return drain(tap(f, stream))
}
/**
* "Run" a stream by creating demand and consuming all events
* @param {Stream<T>} stream stream to drain
* @return {Promise} promise that fulfills after the stream ends without
* an error, or rejects if the stream ends with an error.
*/
export function drain (stream) {
return run(stream.source)
}