Combine `.receive(on: RunLoop.main)` loses sent value. How can I make it work?

I am experiencing the same issue. Specifically we are wanting to run a publisher that performs an expensive operation on a background thread while receiving the results on the main queue. It appears to be a bug in the framework but any workarounds are appreciated! (edit: read too fast and missed that this might be fixed in the Xcode 11.3 beta—will check there—thanks!)

Followup: I tested this against Xcode 11.3 beta 1 in Playgrounds and the issue is still present. Workarounds/fixes appreciated!

let a = PassthroughSubject<Int, Never>()
let b = PassthroughSubject<String, Never>()

let c = a
    .map { a -> Int in
        RunLoop.current.run(until: Date().addingTimeInterval(1))
        return a
    }
    .subscribe(on: DispatchQueue.global())
    .receive(on: DispatchQueue.main)
    
let cancellable = Publishers.CombineLatest(b, c).sink {
    print("b, c", $0, $1)
}

a.send(3)
b.send("3")
1 Like