Skip to content
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

Merged
merged 1 commit into from
Jun 23, 2020

Conversation

zach-klippenstein
Copy link
Collaborator

@zach-klippenstein zach-klippenstein commented Jun 16, 2020

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.

Checklist

  • Unit Tests
  • UI Tests (will be covered by existing UI tests when workers are migrated)
  • I have made corresponding changes to the documentation

@zach-klippenstein zach-klippenstein added this to the v1.0.0 milestone Jun 16, 2020
@zach-klippenstein zach-klippenstein force-pushed the zachklipp/guwt-side-effect branch 3 times, most recently from f97d8f4 to 942884f Compare June 18, 2020 02:13
@zach-klippenstein zach-klippenstein changed the title WIP GUWT step 1: Implement runningSideEffect API GUWT step 1: Implement runningSideEffect API Jun 18, 2020
@zach-klippenstein zach-klippenstein force-pushed the zachklipp/guwt-side-effect branch from 942884f to a5e19d2 Compare June 18, 2020 02:13
@zach-klippenstein zach-klippenstein requested a review from rjrjr June 18, 2020 02:14
@zach-klippenstein zach-klippenstein marked this pull request as ready for review June 18, 2020 02:14
@zach-klippenstein zach-klippenstein requested a review from a team June 18, 2020 02:14
@zach-klippenstein zach-klippenstein force-pushed the zachklipp/guwt-side-effect branch 2 times, most recently from b6a67a4 to 7bb3536 Compare June 18, 2020 03:13
@zach-klippenstein
Copy link
Collaborator Author

This PR is ready for review.

@zach-klippenstein zach-klippenstein force-pushed the zachklipp/guwt-side-effect branch 2 times, most recently from b78ebf3 to 65587b5 Compare June 18, 2020 17:41
zach-klippenstein added a commit that referenced this pull request Jun 19, 2020
…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.
@zach-klippenstein zach-klippenstein changed the title GUWT step 1: Implement runningSideEffect API Introduce runningSideEffect API Jun 19, 2020
@zach-klippenstein zach-klippenstein force-pushed the zachklipp/guwt-side-effect branch from 65587b5 to a25ef3d Compare June 20, 2020 16:56
zach-klippenstein added a commit that referenced this pull request Jun 20, 2020
…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.
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.
@zach-klippenstein zach-klippenstein force-pushed the zachklipp/guwt-side-effect branch from a25ef3d to a5906f9 Compare June 20, 2020 20:41
@@ -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 {
Copy link
Contributor

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?

Copy link
Collaborator Author

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 😅

@zach-klippenstein zach-klippenstein merged commit d974a17 into main Jun 23, 2020
@zach-klippenstein zach-klippenstein deleted the zachklipp/guwt-side-effect branch June 23, 2020 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants