It is possible to `await send(.action)` while .run effect stack be completed?

I attempt to run the next code part. But it does not await completion of .checkConnectionQuality and sends two calls in a row. Is there a way to run this code in a queue one by one?

I've tried . concatenate but looks like it has the same effect.

          case .synchronize:
                return .run {
                    send in
                    await send(.checkConnectionQuality)
                    await send(.checkConnectionQuality)
                }

          case .checkConnectionQuality:
                state.qualityTest = .undefined
                
                guard reachability.isAvailable else {
                    return .send(
                        .connectionQuality(quality: .notConnected))
                }
                
                return .run { send in
                    do {
                        let result = try await networkQuality.networkConnectionTest()
                        switch result {
                        case .success(let speed):
                            await send(
                                .connectionQuality(quality:
                                        .measure(speed: speed)))
                            break
                        case .failure(_):
                            await send(
                                .connectionQuality(quality: .notConnected))
                            break
                        }
                    } catch {
                        await send(
                            .connectionQuality(quality: .notConnected))
                    }
                }

Hey @ObranS !

have you already tried to group your effects? Here it is an example from TCA repository.

I hope it helps!

1 Like

How important is it for state.qualityTest to be set to undefined?
I would recommend taking the code inside your in-line EffectTask (everything in .run) and putting into a separate function so it can be re-used for other actions. That way you wouldn't need the checkConnectionQuality action and can call your new dedicated EffectTask function wherever it's needed.

1 Like

Thank you a lot! Your approach solved this.