Skip to content

Commit

Permalink
Fix some sendable warnings (#174)
Browse files Browse the repository at this point in the history
* Fix some sendability warnings.

* wip

* wip

* wip

* wip

* wip

* wip
  • Loading branch information
mbrandonw committed Jan 23, 2024
1 parent adb04a8 commit e35f125
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions Tests/DependenciesTests/DependencyValuesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,12 @@ final class DependencyValuesTests: XCTestCase {
self.wait(for: [expectation], timeout: 1)
}

#if !os(Linux)
@MainActor
func testEscapingInFeatureModel_InstanceVariablePropagated() {
let expectation = self.expectation(description: "escape")

@MainActor
class FeatureModel /*: ObservableObject*/ {
@Dependency(\.fullDependency) var fullDependency
func doSomething(expectation: XCTestExpectation) {
Expand All @@ -416,6 +419,7 @@ final class DependencyValuesTests: XCTestCase {
model.doSomething(expectation: expectation)
self.wait(for: [expectation], timeout: 1)
}
#endif

func testEscapingInFeatureModel_NotPropagated() async {
let expectation = self.expectation(description: "escape")
Expand Down Expand Up @@ -654,7 +658,7 @@ final class DependencyValuesTests: XCTestCase {
let taskCount = 10

for _ in 1...runCount {
defer { CountInitDependency.initCount = 0 }
defer { CountInitDependency.initCount.setValue(0) }
await withDependencies {
$0 = .test
} operation: {
Expand All @@ -667,17 +671,17 @@ final class DependencyValuesTests: XCTestCase {
}
for await _ in group {}
}
XCTAssertEqual(CountInitDependency.initCount, 1)
XCTAssertEqual(CountInitDependency.initCount.value, 1)
}
}
}
}

struct CountInitDependency: TestDependencyKey {
static var initCount = 0
var fetch: () -> Int
static let initCount = LockIsolated(0)
var fetch: @Sendable () -> Int
static var testValue: Self {
initCount += 1
initCount.withValue { $0 += 1 }
return Self { 42 }
}
}
Expand Down Expand Up @@ -790,7 +794,7 @@ struct ReuseClient: TestDependencyKey {
}
}

private struct FullDependency: DependencyKey {
private struct FullDependency: DependencyKey, Sendable {
var value: Int
static var liveValue: FullDependency {
Self(value: 1)
Expand Down
6 changes: 3 additions & 3 deletions Tests/DependenciesTests/ResolutionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private struct LazyChildDependency: TestDependencyKey {
static let testValue = Self { 1729 }
}
private struct NestedParentDependency: TestDependencyKey {
var value: () -> Int
var value: @Sendable () -> Int
static var testValue: NestedParentDependency {
@Dependency(\.nestedChild) var child
return Self {
Expand All @@ -249,7 +249,7 @@ private struct NestedParentDependency: TestDependencyKey {
}
}
private struct NestedChildDependency: TestDependencyKey {
var value: () -> Int
var value: @Sendable () -> Int
static let testValue = Self { 1729 }
}
private struct DiamondDependencyA: TestDependencyKey {
Expand Down Expand Up @@ -294,7 +294,7 @@ private struct CyclicDependency2: TestDependencyKey {
}
private struct ClientWithDependency: TestDependencyKey {
@Dependency(\.eagerChild) var eagerChild
var onValue: (EagerChildDependency) -> Int = { $0.value }
var onValue: @Sendable (EagerChildDependency) -> Int = { $0.value }
func value() -> Int {
self.onValue(self.eagerChild)
}
Expand Down

0 comments on commit e35f125

Please sign in to comment.