-
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
Consider version of initialState
that provides a CoroutineScope
identical to the WorkflowNode
's
#990
Comments
Thinking about this more... we have had 2 main use cases for a StateFlow :
So now I've convinced myself that I don't see a case where we need |
Case one is less interesting now that #992 has landed, but this still seems like it would solve a lot of other problems. |
CoroutineScope
identical to the WorkflowNode'sinitialState
that provides a CoroutineScope
identical to the WorkflowNode
's
In terms of discoverability and having good tools 'at hand' you mean? I feel like I've ruled out what I thought before were the main use cases in terms of being blocked without this. |
You have a much clearer picture of the situation than I do. Let's definitely not build this until we have real people with real use cases in hand. |
I have a case where I need a CoroutineScope that lasts for the duration of a workflow. I need a scope and object from a callback in order to create a new state. With the current implementation it's going to look like something like this on the render function context.runningSideEffect("scope") {
val scope = this
context.actionSink.send(action {
val newState = state.result?.let { NewState(NewObject(scope, it))}
val oldState = state.copy(scope = scope)
state = newState ?: oldState
})
// suspend forever
}
return Rendering(
onObjectCreated = context.eventHandler {
val newState = state.scope?.let { NewState(NewObject(it, result))}
val oldState = state.copy(result = result)
state = newState ?: oldState
}
) This creates a funky race condition where I have to keep track of two callbacks and having a |
From an offline conversation with @steve-the-edwards: public abstract class SessionWorkflow<
SessionT,
in PropsT,
StateT,
out OutputT,
out RenderingT
> : Workflow<PropsT, OutputT, RenderingT>, IdCacheable {
public abstract fun onSessionStarted(scope: CoroutineScope): SessionT
public abstract fun initialState(
session: SessionT,
props: PropsT,
snapshot: Snapshot?
): StateT
public abstract fun render(
session: SessionT,
renderProps: PropsT,
renderState: StateT,
context: RenderContext
): RenderingT public abstract class StatefulWorkflow<
in PropsT,
StateT,
out OutputT,
out RenderingT
> : SessionWorkflow<Unit, PropsT, OutputT, RenderingT>, IdCacheable
public final fun initialState(
session: SessionT,
props: PropsT,
snapshot: Snapshot?
): StateT = initialState(props, snapshot)
public abstract final initialState(
props: PropsT,
snapshot: Snapshot
): StateT
One big idea here is that I like the idea of |
So now the next question is: do we really need So did I just talk myself back into the original plan of simply adding a |
Note that |
Perhaps, because without a notion of |
Then for example, a StateFlow operator could be launched from onInitialState under a scope identical to the workflow's scope.
The text was updated successfully, but these errors were encountered: