Waiting with state modification until another action finishes

I have the following case. One of the Tabs in my app can display a sheet and in this sheet some computation is being performed which may fail, so this tab also handles alert. I've implemented AlertData as this Tabs state, so once I catch this error case in reducer, I want to hide this sheet (perform some side effects at this stage as well) and display alert only after finishing the previous step. Here's the snippet from my reducer.

case let .discoveredDevice(.failure(discoveryError)):
                if case Error.scanningTimeout = discoveryError {
                    state.alertData = AlertData(title: "Scanning timed out")
                }
                return Effect(value: .hideScanningModal)

SwiftUI complaints that this view is already presenting another view, so that Alert cannot be presented on top. How can I delay or concatenate those Effects, so that I achieve the correct behaviour?


After some messing around, I came up with the following solution. I've created another action called .showAlert(AlertData) and this one modifies the alert related state. Also, I've modified .discoveredDevice(.failure) to something like this:

case let .discoveredDevice(.failure(discoveryError)):
                if case Error.scanningTimeout = discoveryError {
                    let alertData = AlertData(title: "Scanning timed out")

                    return Effect.concatenate(
                        Effect(value: .hideScanningModal),
                        Effect(value: .showAlert(data: alertData))
                            .delay(for: 1, scheduler: environment.mainQueue)
                            .eraseToEffect()
                    )
                }

                return .none

I don't know if that's the correct of dealing with such stuff, but it works. The only thing that buggers me is this delay, but I think what can be done do avoid this is somehow listening to the animation completion, but I'm not sure if this is possible with the current state of SwiftUI.