pull-resolve
Library to wrap pull-stream
sinks and await the result.
Usage
A basic resolver just wraps pull.onEnd
. This lets you wait until a pull-stream has finished, and move on or catch errors accordingly.
var pull = var resolve = { var stream = try await // Move on catch err // Handle errors }
Builtin sinks
In addition to pull.onEnd
, this library ships with a couple of plugins to support other builtin pull-stream sinks as well.
collect()
This plugin is used without arguments.
var collect = var pull = var resolve = { var stream = pull var result = await console // [1, 2, 3]}
concat()
This plugin is used without arguments.
var concat = var pull = var resolve = { var stream = pull var result = await console // 'somestuff'}
find(test?: function)
This plugin takes a test function as argument, just like Array.prototype.find
.
var find = var pull = var resolve = { var stream = pull var result = await console // 'mysterious'}
reduce(reducer: function, accumulator?: any)
This plugin takes a reducer function and an optional accumulator value as arguments, just like Array.prototype.reduce
.
var pull = var reduce = var resolve = { var stream = pull var resolve = await console // 20}
Advanced sinks
You can wrap any pull-stream sink and plug it into a resolver. This example using pull-level
demonstrates the correct pattern:
var level = var pull = var resolve = { return { return level }} { var stream = pull try await // move on catch err // handle errors }
Compatibility
If async/await
isn't supported in your environment, you can use the promise directly:
License
Apache-2.0