Feature: Bluebird streams
See original GitHub issueA lot of the bluebird feature requests deal with lists and iterables and various methods to execute them. Proposals include sequential iteration, concurrency controls (#1100), infinite list iteration (#1143) and so on.
In my opinion, adding new array/iterable methods is neither elegant (utility grab bag) nor efficient (entire arrays are allocated and held in memory even when there is no reason to do that).
Bluebrid would benefit from a compatible object stream library that works well with it. A good place to start would be the Dart stream API - its designed incredibly well. Promise-related feature highlights:
asyncMap
- like map, but returned promises are assimilated.asyncExpand
- this would simply be flatMapany
/firstWhere
/fold
/join
etc - we could use JS Array method names such asincludes
/reduce
when equivalents existtoList
/toSet
could also have equivalents (toArray
,toSet
)
Concurrency limits don’t exist in Dart, and the API I implemented in promise-streams is fairly clunky:
https://github.com/spion/promise-streams
Some other random benefits from the integration:
promise.asStream()
, which would be the equivalent of Dart’s Future.asStreampromise.unpackStream()
- converts aPromise<Stream<T>>
to aStream<T>
Motivating code example:
api.search('query')
.then(resultPage => Stream.iterate(page => page.getNextPage(), resultPage))
.unpackStream()
.flatMap(page => page.getImageUrls())
.asyncMap(url => download(img), {concurrency: 8})
.asyncReduce((accumulatedImage, img) => stitchImage(accumulatedImage, img))
Other ideas on how this library could be designed are collected here: https://gist.github.com/spion/ecdc92bc5de5b381da30
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:18 (1 by maintainers)
@benjamingr well, try it out on the example I gave. I think the fluent API makes a big difference.
There is also promise.toStream() as well as many stream methods above that return a promise (
any
,first
,firstWhere
,last
,all
,toArray
and many more)(Really, can’t wait for the bind operator to come soon enough!)
Another library to check out: https://github.com/RubenVerborgh/AsyncIterator