-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coroutine flow support #233
Conversation
2f10a0e
to
3261255
Compare
formula-coroutines/src/main/java/com/instacart/formula/coroutines/FlowRuntime.kt
Show resolved
Hide resolved
formula-coroutines/src/main/java/com/instacart/formula/coroutines/FlowStream.kt
Outdated
Show resolved
Hide resolved
...les/stopwatch-coroutines/src/main/java/com/instacart/formula/stopwatch/StopWatchViewModel.kt
Outdated
Show resolved
Hide resolved
...les/stopwatch-coroutines/src/main/java/com/instacart/formula/stopwatch/StopWatchViewModel.kt
Show resolved
Hide resolved
@Test | ||
fun `increment 5 times`() = test { | ||
|
||
StopwatchFormula(this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to have such a tests within formula-coroutines
module to cover toFlow()
and FlowStream.fromFlow {}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added tests for FlowRuntime
and FlowStream
. I know you were trying to decide if it still made sense to have per runtime specific tests, but we can always remove them. I added TestFlow
to serve the purpose of Rx's TestObserver
. I know square came out with Turbine, but it felt like an overkill.
First of all, thank you for this contribution 🙌 Overall, it looks pretty solid.
We generally want
This approach has been working well for us, but the issues you bring up are valid.
I have been thinking about this a little bit, not yet sure what is the best option here. For more context, the RxJava version is used only internally within |
formula-coroutines/src/main/java/com/instacart/formula/coroutines/FlowRuntime.kt
Outdated
Show resolved
Hide resolved
samples/counter-coroutines/src/main/java/com/instacart/formula/counter/CounterActivity.kt
Outdated
Show resolved
Hide resolved
8f128d2
to
ec4739d
Compare
…tially calling terminate() twice. (EO)
…TestFlow as a counterpart to TestObserver. (EO)
321803f
to
87aa472
Compare
Closing this as we merged #240 |
This should help with adding support for coroutines as mentioned in #231
A couple of things to note:
channel
field incallbackFlow{}
in order to comply to theonError
argument forFormulaRuntime
. Usingcancel()
on theProducerScope
is not possible since it takes aCancellableException
and not aThrowable
.onClear()
and to dispose of the consumer subscirption insideonDestroy()
of the Activity. If I am not mistaken it seems that this can lead to two dangerous scenarios:onStop()
.repeatOnLifecycle{}
in combination withSharingStarted.WhileSubscribed()
. This approach not only stops/starts collection, but also cancels the producer on the required lifecycle when there are no more collectors.repeatOnLifecycle{}
uses an alpha release of the lifecycle runtime dependency.StopWatchFormula
just as an example of how testing a flow might look like. It is probably better to add Flow testing capabilities toformula-test
just like it is done for rx.