-
Notifications
You must be signed in to change notification settings - Fork 110
Open
Description
I could be doing something wrong in my interceptor, but it doesn't seem as though the debugging name used by WorkflowAction
s that handle the result of a Worker
are bubbling up to the WorkflowInterceptor
. I have some minimal reproducible example code below:
package com.stripe.reader.application
import com.squareup.workflow1.BaseRenderContext
import com.squareup.workflow1.Worker
import com.squareup.workflow1.Workflow
import com.squareup.workflow1.WorkflowAction
import com.squareup.workflow1.WorkflowInterceptor
import com.squareup.workflow1.WorkflowInterceptor.RenderContextInterceptor
import com.squareup.workflow1.action
import com.squareup.workflow1.renderWorkflowIn
import com.squareup.workflow1.runningWorker
import com.squareup.workflow1.stateless
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collect
import kotlin.system.exitProcess
suspend fun main() = coroutineScope {
val workflow: Workflow<Unit, Unit, String> = Workflow.stateless {
runningWorker(Worker.timer(1000L)) {
action("wait-completed") { setOutput(Unit) }
}
"Waiting for input..."
}
val interceptor = object : WorkflowInterceptor {
override fun <P, S, O, R> onRender(
renderProps: P,
renderState: S,
context: BaseRenderContext<P, S, O>,
proceed: (P, S, RenderContextInterceptor<P, S, O>?) -> R,
session: WorkflowInterceptor.WorkflowSession
): R {
println("onRender: $renderState")
val contextInterceptor = object : RenderContextInterceptor<P, S, O> {
override fun onActionSent(
action: WorkflowAction<P, S, O>,
proceed: (WorkflowAction<P, S, O>) -> Unit
) {
println("onActionSent: ${action.debuggingName}")
proceed(action)
}
}
return proceed(renderProps, renderState, contextInterceptor)
}
}
renderWorkflowIn(
workflow = workflow,
scope = this@coroutineScope,
interceptors = listOf(interceptor),
props = MutableStateFlow(Unit),
onOutput = { exitProcess(0) },
).collect()
}
That seems to produce the following output:
onRender: kotlin.Unit
onRender: 0
onActionSent: EmitWorkerOutputAction(worker=TimerWorker(delayMs=1000, key=), key=)
onRender: kotlin.Unit
onRender: 0
I was hoping that the "wait-completed"
string would be present in that output body but it seems like it's possibly dropped somewhere in the Worker → WorkerWorkflow translation and being replaced with something else. I realize I can still use this string as the Worker's key and have it show up there as a workaround, but still feels odd considering I'm required to provide a name here (even though it's unused).
Metadata
Metadata
Assignees
Labels
No labels