@@ -192,9 +192,11 @@ private class RootScopeImpl<PropsT, OutputT>(
192192) : RootScope<PropsT, OutputT>, CoroutineScope by coroutineScope {
193193
194194 override fun emitOutput (output : OutputT ) {
195- actionSink.send(action(" emitOutput" ) {
196- setOutput(output)
197- })
195+ actionSink.send(
196+ action(" emitOutput" ) {
197+ setOutput(output)
198+ }
199+ )
198200 }
199201
200202 override suspend fun <ChildPropsT , ChildOutputT , R > showWorkflow (
@@ -219,9 +221,11 @@ private class ShowWorkflowChildScopeImpl<PropsT, OutputT, R>(
219221) : ShowWorkflowChildScope<OutputT, R>, CoroutineScope by coroutineScope {
220222
221223 override fun emitOutput (output : OutputT ) {
222- actionSink.send(action(" emitOutput" ) {
223- setOutput(output)
224- })
224+ actionSink.send(
225+ action(" emitOutput" ) {
226+ setOutput(output)
227+ }
228+ )
225229 }
226230
227231 @Suppress(" UNCHECKED_CAST" )
@@ -256,7 +260,9 @@ private class Frame<PropsT, OutputT, ChildPropsT, ChildOutputT, R>(
256260 private val props : ChildPropsT ,
257261 private val callerJob : Job ,
258262 val frameScope : CoroutineScope ,
259- private val onOutput : suspend ShowWorkflowChildScopeImpl <PropsT , OutputT , R >.(ChildOutputT ) -> Unit ,
263+ private val onOutput : suspend ShowWorkflowChildScopeImpl <PropsT , OutputT , R >.(
264+ ChildOutputT
265+ ) -> Unit ,
260266 private val actionSink : Sink <WorkflowAction <PropsT , ThingyState , OutputT >>,
261267 private val parent : Frame <* , * , * , * , * >? ,
262268) {
@@ -276,22 +282,24 @@ private class Frame<PropsT, OutputT, ChildPropsT, ChildOutputT, R>(
276282 * Pops everything off the stack that comes after this.
277283 */
278284 fun popTo () {
279- actionSink.send(action(" popTo" ) {
280- val stack = state.stack
281- val index = stack.indexOf(this @Frame)
282- check(index != - 1 ) { " Frame was not in the stack!" }
283-
284- // Cancel all the frames we're about to drop, starting from the top.
285- for (i in stack.lastIndex downTo index + 1 ) {
286- // Don't just cancel the frame job, since that would only cancel output handlers the frame
287- // is running. We want to cancel the whole parent's output handler that called showWorkflow,
288- // in case the showWorkflow is in a try/catch that tries to make other suspending calls.
289- stack[i].callerJob.cancel()
290- }
285+ actionSink.send(
286+ action(" popTo" ) {
287+ val stack = state.stack
288+ val index = stack.indexOf(this @Frame)
289+ check(index != - 1 ) { " Frame was not in the stack!" }
290+
291+ // Cancel all the frames we're about to drop, starting from the top.
292+ for (i in stack.lastIndex downTo index + 1 ) {
293+ // Don't just cancel the frame job, since that would only cancel output handlers the frame
294+ // is running. We want to cancel the whole parent's output handler that called showWorkflow,
295+ // in case the showWorkflow is in a try/catch that tries to make other suspending calls.
296+ stack[i].callerJob.cancel()
297+ }
291298
292- val newStack = stack.take(index + 1 )
293- state = state.copy(stack = newStack)
294- })
299+ val newStack = stack.take(index + 1 )
300+ state = state.copy(stack = newStack)
301+ }
302+ )
295303 }
296304
297305 private fun onOutput (output : ChildOutputT ): WorkflowAction <PropsT , ThingyState , OutputT > {
@@ -325,9 +333,11 @@ private class Frame<PropsT, OutputT, ChildPropsT, ChildOutputT, R>(
325333 // This will eventually cancel the frame scope.
326334 result.complete(it)
327335 // TODO figure out how to coalesce this action into the one for showWorkflow. WorkStealingDispatcher?
328- sink.send(action(" unshowWorkflow" ) {
329- state = state.removeFrame(this @Frame)
330- })
336+ sink.send(
337+ action(" unshowWorkflow" ) {
338+ state = state.removeFrame(this @Frame)
339+ }
340+ )
331341 },
332342 thisFrame = this @Frame,
333343 parentFrame = parent
@@ -358,26 +368,30 @@ private suspend fun <PropsT, OutputT, ChildPropsT, ChildOutputT, R> showWorkflow
358368 lateinit var frame: Frame <PropsT , OutputT , ChildPropsT , ChildOutputT , R >
359369
360370 // Tell the workflow runtime to start rendering the new workflow.
361- actionSink.sendAndAwaitApplication(action(" showWorkflow" ) {
362- frame = Frame (
363- workflow = workflow,
364- props = props,
365- callerJob = callerJob,
366- frameScope = frameScope,
367- onOutput = onOutput,
368- actionSink = actionSink,
369- parent = parentFrame,
370- )
371- state = state.appendFrame(frame)
372- })
371+ actionSink.sendAndAwaitApplication(
372+ action(" showWorkflow" ) {
373+ frame = Frame (
374+ workflow = workflow,
375+ props = props,
376+ callerJob = callerJob,
377+ frameScope = frameScope,
378+ onOutput = onOutput,
379+ actionSink = actionSink,
380+ parent = parentFrame,
381+ )
382+ state = state.appendFrame(frame)
383+ }
384+ )
373385
374386 return try {
375387 frame.awaitResult()
376388 } finally {
377389 frameScope.cancel()
378- actionSink.send(action(" unshowWorkflow" ) {
379- state = state.removeFrame(frame)
380- })
390+ actionSink.send(
391+ action(" unshowWorkflow" ) {
392+ state = state.removeFrame(frame)
393+ }
394+ )
381395 }
382396}
383397
0 commit comments