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

Workflow host observers are notified before internal updates are finished #289

Open
bolderkat opened this issue Jul 24, 2024 · 0 comments
Open

Comments

@bolderkat
Copy link

Scenario

Say I am hosting a Workflow in a UIViewController using a WorkflowHostingController. In the view controller, I am observing the output of my Workflow with something like:

hostingController.output.take(during: lifetime).observeValues { [weak self] output in
    guard let self else { return }

    switch output {
    case .somethingChanged(let foo):
        self.foo = foo
    }
}

If I need to pass the new value of foo back into the Workflow, and I try to update the Workflow synchronously, e.g. by calling:

hostingController.update(workflow: MyWorkflow(foo: foo))

then this consistently results in a crash: Fatal error: EventPipe can only be enabled from the `pending` state

A suggestion by @jamieQ is that "we could potentially delay notifying the workflow host observers until after all the internal updates were finished."

Workarounds

We can avoid the crash by delaying event handling, either when observing the Workflow output:

hostingController.output.take(during: lifetime).observe(on: QueueScheduler.main).observeValues {
    // ...
}

or when updating the Workflow:

DispatchQueue.main.async { [weak self] in
    guard let self else { return }
    self.hostingController.update(workflow: MyWorkflow(foo: foo))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant