Skip to content

Commit e74ea26

Browse files
stephencelismbrandonw
authored andcommitted
Thread messaging (#803)
* Use thread dictionary for check instead * Improve thread check messaging for Store.scope * typo fix Co-authored-by: Brandon Williams <[email protected]>
1 parent ef02241 commit e74ea26

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Sources/ComposableArchitecture/Store.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ public final class Store<State, Action> {
291291
state toLocalState: @escaping (State) -> LocalState,
292292
action fromLocalAction: @escaping (LocalAction) -> Action
293293
) -> Store<LocalState, LocalAction> {
294+
self.threadCheck(status: .scope)
294295
var isSending = false
295296
let localStore = Store<LocalState, LocalAction>(
296297
initialState: toLocalState(self.state),
@@ -436,6 +437,7 @@ public final class Store<State, Action> {
436437

437438
private enum ThreadCheckStatus {
438439
case effectCompletion(Action)
440+
case scope
439441
case send(Action, isFromViewStore: Bool)
440442
}
441443

@@ -449,22 +451,28 @@ public final class Store<State, Action> {
449451
switch status {
450452
case let .effectCompletion(action):
451453
message = """
452-
An effect returned from the action "\(debugCaseOutput(action))" completed on the \
453-
wrong thread. Make sure to use ".receive(on:)" on any effects that execute on background \
454+
An effect returned from the action "\(debugCaseOutput(action))" completed on the wrong \
455+
thread. Make sure to use ".receive(on:)" on any effects that execute on background \
454456
threads to receive their output on the same thread the store was created on.
455457
"""
456458

459+
case .scope:
460+
message = """
461+
"Store.scope" was called on the wrong thread. Make sure that "Store.scope" is always \
462+
called on the same thread the store was created on.
463+
"""
464+
457465
case let .send(action, isFromViewStore: true):
458466
message = """
459-
"ViewStore.send(\(debugCaseOutput(action)))" was called on the wrong thread. Make \
460-
sure that "ViewStore.send" is always called on the same thread the store was created on.
467+
"ViewStore.send(\(debugCaseOutput(action)))" was called on the wrong thread. Make sure \
468+
that "ViewStore.send" is always called on the same thread the store was created on.
461469
"""
462470

463471
case let .send(action, isFromViewStore: false):
464472
message = """
465-
An effect emitted the action "\(debugCaseOutput(action))" from the wrong thread. Make sure \
466-
to use ".receive(on:)" on any effects that execute on background threads to receive their \
467-
output on the same thread the store was created on.
473+
An effect emitted the action "\(debugCaseOutput(action))" from the wrong thread. Make \
474+
sure to use ".receive(on:)" on any effects that execute on background threads to receive \
475+
their output on the same thread the store was created on.
468476
"""
469477
}
470478

0 commit comments

Comments
 (0)