stream_transform icon indicating copy to clipboard operation
stream_transform copied to clipboard

Add a optional parameter 'waitAll' on combineLatestAll

Open tpouriel opened this issue 2 years ago • 4 comments

Allow combineLastestAll output stream to emit events even if all the input streams don't have emitted yet.

tpouriel avatar May 23 '23 15:05 tpouriel

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar May 23 '23 15:05 google-cla[bot]

I can provide more tests, docs and bump version if this base modification looks good to you...

tpouriel avatar May 23 '23 15:05 tpouriel

Can you describe your use case?

natebosch avatar May 24 '23 15:05 natebosch

My usecase is the following : I have a source stream emitting events describing the state of a model in a database. The stream is consumed by a consumer, typically a Widget. In between I have a some "middlewares" that inject more stuff into the model, but some of the middleware can be quite slow if they have a lot of computation.

Here is what it looks like :

class Model {
...
}

interface Producer {
   Stream<List<Model>> streamFromDb();
}

interface Middleware {
   Stream<List<Model>> applyModification(Stream<List<Model>> source);
}

class StreamManager {
   final List<Middleware> middlewares = [...];
   final Producer producer;
   
   Stream<List<Model>> getAugmentedStream() {
      final source = producer.streamFromDb().asBroadcastStream();
     return middlewares.first.applyModification(source).combineLatestAll(middlewares.subList(1).map((middleware) => middleware.applyModification(source)).map(_resolveModifications);
   }
}

interface Consumer  {
   // getAugmentedStream is called here
}

tpouriel avatar May 24 '23 16:05 tpouriel