-
Notifications
You must be signed in to change notification settings - Fork 101
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
Introduce runningSideEffect API #12
Conversation
f97d8f4
to
942884f
Compare
942884f
to
a5e19d2
Compare
b6a67a4
to
7bb3536
Compare
This PR is ready for review. |
workflow-runtime/src/main/java/com/squareup/workflow/internal/RealRenderContext.kt
Show resolved
Hide resolved
workflow-runtime/src/main/java/com/squareup/workflow/internal/WorkflowNode.kt
Outdated
Show resolved
Hide resolved
workflow-runtime/src/main/java/com/squareup/workflow/internal/WorkflowNode.kt
Outdated
Show resolved
Hide resolved
workflow-runtime/src/main/java/com/squareup/workflow/internal/WorkflowNode.kt
Show resolved
Hide resolved
workflow-runtime/src/main/java/com/squareup/workflow/internal/SideEffectNode.kt
Outdated
Show resolved
Hide resolved
b78ebf3
to
65587b5
Compare
…end functions. - `Sink.sendAndAwaitApplication()` - `Flow.collectToSink()` These helpers will be used to implement Workers using side effects (#12). GUWT workers are described in square/workflow#1021.
65587b5
to
a25ef3d
Compare
…end functions. - `Sink.sendAndAwaitApplication()` - `Flow.collectToSink()` These helpers will be used to implement Workers using side effects (#12). GUWT workers are described in square/workflow#1021.
workflow-core/src/main/java/com/squareup/workflow/RenderContext.kt
Outdated
Show resolved
Hide resolved
First part of Kotlin implementation of square/workflow#1021. Kotlin counterpart to square/workflow#1174. This implementation intentionally does not run the side effect coroutine on the `workerContext` `CoroutineContext` that is threaded through the runtime for testing infrastructure. Initially, workers ran in the same context as the workflow runtime. The behavior of running workers on a different dispatcher by default (`Unconfined`) was introduced in square/workflow#851 as an optimization to reduce the overhead for running workers that only perform wiring tasks with other async libraries. This was a theoretical optimization, since running on the `Unconfined` dispatcher inherently involves less dispatching work, but the overhead of dispatching wiring coroutines was never actually shown to be a problem. Additionally, because tests often need to be in full control of dispatchers, the ability to override the context used for workers was introduced in square/workflow#940, which introduced `workerContext`. I am dropping that complexity here because it adds a decent amount of complexity to worker/side effect machinery without any proven value. It is also complexity that needs to be documented, and is probably just more confusing than anything. The old behavior for workers is maintained for now to reduce the risk of this change, but side effects will always run in the workflow runtime's context. This is nice and simple and unsurprising and easy to reason about.
a25ef3d
to
a5906f9
Compare
@@ -63,7 +67,7 @@ internal class WorkflowNode<PropsT, StateT, OutputT : Any, RenderingT>( | |||
private val idCounter: IdCounter? = null, | |||
initialState: StateT? = null, | |||
private val workerContext: CoroutineContext = EmptyCoroutineContext | |||
) : CoroutineScope, WorkerRunner<StateT, OutputT> { | |||
) : CoroutineScope, WorkerRunner<StateT, OutputT>, SideEffectRunner { |
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.
Out of scope (ahem) for this PR, but: I forgot that this class implements CoroutineScope
directly. Isn't that discouraged these days?
Have we already had this conversation?
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.
You are very right. I already fixed it in one of the other 300 branches I put up this weekend but i forget which one 😅
First part of Kotlin implementation of square/workflow#1021.
Kotlin counterpart to square/workflow#1174.
This implementation intentionally does not run the side effect coroutine
on the
workerContext
CoroutineContext
that is threaded through theruntime for testing infrastructure. Initially, workers ran in the same
context as the workflow runtime. The behavior of running workers on a
different dispatcher by default (
Unconfined
) was introduced insquare/workflow#851 as an optimization to reduce
the overhead for running workers that only perform wiring tasks with
other async libraries. This was a theoretical optimization, since running
on the
Unconfined
dispatcher inherently involves less dispatching work,but the overhead of dispatching wiring coroutines was never actually shown
to be a problem. Additionally, because tests often need to be in full
control of dispatchers, the ability to override the context used for
workers was introduced in square/workflow#940,
which introduced
workerContext
. I am dropping that complexity herebecause it adds a decent amount of complexity to worker/side effect
machinery without any proven value. It is also complexity that needs to
be documented, and is probably just more confusing than anything. The
old behavior for workers is maintained for now to reduce the risk of this
change, but side effects will always run in the workflow runtime's
context. This is nice and simple and unsurprising and easy to reason
about.
Checklist
UI Tests(will be covered by existing UI tests when workers are migrated)