-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Bucket effect cancel IDs. * wip * wip * remove cache reset * wip * wip * wip
- Loading branch information
Showing
9 changed files
with
110 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Tests/ComposableArchitectureTests/EffectCancellationIsolationTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#if canImport(Testing) | ||
import ComposableArchitecture | ||
import Testing | ||
|
||
@Suite | ||
struct EffectCancellationIsolationTests { | ||
@Test | ||
func testIsolation1() async { | ||
let store = await TestStore(initialState: Feature.State()) { | ||
Feature() | ||
} | ||
await store.send(.start) | ||
await store.receive(\.response) { | ||
$0.value = 42 | ||
} | ||
await store.send(.stop) | ||
} | ||
|
||
@Test | ||
func testIsolation2() async { | ||
let store = await TestStore(initialState: Feature.State()) { | ||
Feature() | ||
} | ||
await store.send(.start) | ||
await store.receive(\.response) { | ||
$0.value = 42 | ||
} | ||
await store.send(.stop) | ||
} | ||
} | ||
|
||
@Reducer | ||
private struct Feature { | ||
struct State: Equatable { | ||
var value = 0 | ||
} | ||
enum Action { | ||
case response(Int) | ||
case start | ||
case stop | ||
} | ||
enum CancelID { case longLiving } | ||
var body: some ReducerOf<Self> { | ||
Reduce { state, action in | ||
switch action { | ||
case .response(let value): | ||
state.value = value | ||
return .none | ||
case .start: | ||
return .run { send in | ||
await send(.response(42)) | ||
try await Task.never() | ||
} | ||
.cancellable(id: CancelID.longLiving, cancelInFlight: true) | ||
case .stop: | ||
return .cancel(id: CancelID.longLiving) | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters