@@ -134,13 +134,10 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn(
134
134
}
135
135
)
136
136
137
- suspend fun <PropsT , OutputT , RenderingT > renderAndEmitOutput (
138
- runner : WorkflowRunner <PropsT , OutputT , RenderingT >,
137
+ suspend fun <OutputT > sendOutput (
139
138
actionResult : ActionProcessingResult ? ,
140
139
onOutput : suspend (OutputT ) -> Unit
141
- ): RenderingAndSnapshot <RenderingT > {
142
- val nextRenderAndSnapshot = runner.nextRendering()
143
-
140
+ ) {
144
141
when (actionResult) {
145
142
is WorkflowOutput <* > -> {
146
143
@Suppress(" UNCHECKED_CAST" )
@@ -150,8 +147,6 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn(
150
147
}
151
148
else -> {} // no -op
152
149
}
153
-
154
- return nextRenderAndSnapshot
155
150
}
156
151
157
152
scope.launch {
@@ -166,14 +161,13 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn(
166
161
// we don't surprise anyone with an unexpected rendering pass. Show's over, go home.
167
162
if (! isActive) return @launch
168
163
169
- // If the action did produce an Output, we send it immediately after the render pass.
170
- nextRenderAndSnapshot = renderAndEmitOutput(runner, actionResult, onOutput)
164
+ nextRenderAndSnapshot = runner.nextRendering()
171
165
172
166
if (runtimeConfig == ConflateStaleRenderings ) {
173
- // With this runtime modification, we do not pass renderings we know to be stale. This
174
- // means that we may be calling onOutput out of sync with the update of the UI. Output
175
- // is an event though, and should always occur immediately - i.e. it cannot be stale .
176
- while (actionResult != ActionsExhausted ) {
167
+ // Only null will allow us to continue processing actions and conflating stale renderings.
168
+ // If this is not null, then we had an Output and we want to send it with the Rendering
169
+ // (stale or not) .
170
+ while (actionResult == null ) {
177
171
// We have more actions we can process, so this rendering is stale.
178
172
actionResult = runner.processAction(waitForAnAction = false )
179
173
@@ -182,12 +176,14 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn(
182
176
// If no actions processed, then no new rendering needed.
183
177
if (actionResult == ActionsExhausted ) break
184
178
185
- nextRenderAndSnapshot = renderAndEmitOutput( runner, actionResult, onOutput )
179
+ nextRenderAndSnapshot = runner.nextRendering( )
186
180
}
187
181
}
188
182
189
183
// Pass on to the UI.
190
184
renderingsAndSnapshots.value = nextRenderAndSnapshot
185
+ // And emit the Output.
186
+ sendOutput(actionResult, onOutput)
191
187
}
192
188
}
193
189
0 commit comments