google / promises

Promises is a modern framework that provides a synchronization construct for Swift and Objective-C.
Apache License 2.0
3.8k stars 293 forks source link

Promises streams #42

Closed ekkotech closed 6 years ago

ekkotech commented 6 years ago

Is it possible to implement a "stream" concept with Promises? What would be the recommended way?

There are many use cases where it is necessary to provide multiple invocations of the then block over the lifetime of a Promise:

Similar behaviour is found in CoreLocation.

SimpleFutures implements the concept of a FutureStream and PromiseStream using an array of responses up to a maximum defined by a capacity parameter. Maybe there is an need for history, maybe not. In the above cases, each new update would supersede all prior updates.

Invalidating a stream would be done either by a timeout (already implemented in Promises) or explicit invalidation by the application.

Any thoughts on this would be welcome. ac

shoumikhin commented 6 years ago

@ekkotech Promises are fundamentally different from reactive streams: they can only be resolved once. To support anything else that could potentially pass multiple values over time we'd need to introduce a separate concept, as you've mentioned. That's currently out of our scope and project goals.