Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Sources/ComposableArchitecture/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,40 @@ public final class Store<State, Action> {

var didComplete = false
let uuid = UUID()

#if DEBUG
let initalThread = Thread.current
initalThread.threadDictionary[uuid] = true
#endif

let effectCancellable = effect.sink(
receiveCompletion: { [weak self] _ in
#if DEBUG
if Thread.current.threadDictionary[uuid] == nil {
breakpoint(
"""
---
Warning: Store.send

The Store class is not thread-safe, and so all interactions with an instance of Store
(including all of its scopes and derived ViewStores) must be done on the same thread.

\(debugCaseOutput(action)) has produced an Effect that was completed on a different thread \
from the one it was executed on.

Starting thread: \(initalThread)
Final thread: \(Thread.current)

Possible fixes for this are:

* Add a .receive(on:) to the Effect to ensure it completes on this Stores correct thread.
"""
)
}

Thread.current.threadDictionary[uuid] = nil
#endif

didComplete = true
self?.effectCancellables[uuid] = nil
},
Expand Down