What thread does Combine `.collect` method emit on?

What is the expected thread on which a .collect operation in Swift's Combine will emit?

Specifically I am seeing this code crash in the second precondition, but not the first:

return Publishers.MergeMany(publishers)
    .handleEvents(receiveOutput: { _ in
        precondition(Thread.isMainThread) // <- This is fine
    })
    .collect()
    .handleEvents(receiveOutput: { _ in
        precondition(Thread.isMainThread) // <- Crash is here
    })

It is as if the .collect operation is picking a different thread to use, even though the final publisher in the MergeMany must have emitted on the main thread. I have deduced this behavior via crash logs uploaded from Firebase. Can anyone explain this observed behavior?

Post not yet marked as solved Up vote post of es1997 Down vote post of es1997
522 views