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

Pass the workflow's scope into initialState. #286

Merged
merged 1 commit into from
Apr 16, 2019

Conversation

zach-klippenstein
Copy link
Collaborator

@zach-klippenstein zach-klippenstein commented Apr 16, 2019

Closes #288.

*/
abstract fun initialState(
input: InputT,
snapshot: Snapshot?
snapshot: Snapshot?,
scope: CoroutineScope
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidapgar @bencochran @timdonnelly Seems like we should be able to come up with a similar object to pass into the analogous method in Swift — basically something that can accept tearDown duties instead of the method on WorkflowContext.

Copy link
Collaborator Author

@zach-klippenstein zach-klippenstein Apr 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not suggesting this is a good direction, but if Swift wanted to match this as accurately as possible, it would be a teardown hook plus a scheduler. Having access to a coroutine scope is useful for us, but given the lack of similar concepts in Swift I'm not sure this would be the best API for them. But curious to hear what yall think!

@@ -71,10 +73,15 @@ abstract class StatefulWorkflow<
* If the workflow is being restored from a [Snapshot], [snapshot] will be the last value
* returned from [snapshotState], and implementations that return something other than
* [Snapshot.EMPTY] should create their initial state by parsing their snapshot.
* @param scope
* The [CoroutineScope] in which this workflow lives. The scope will be cancelled when the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we provide an example of how to use it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what kind of example would be useful. It's basically only there to support Workers (which users don't need to care about unless they want to look at source directly), or cancellation of some external resource, and I don't even know yet what the best way will be to use this scope to cancel those. I'll file an issue to track improving this doc as we go forward: #290.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kotlin Affects the Kotlin library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pass the workflow's coroutine scope into StatefulWorkflow.initialState.
2 participants