Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into navigation-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Mar 21, 2023
2 parents 24abb35 + 619cb40 commit 553214e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Sources/ComposableArchitecture/Effects/Publisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ extension EffectPublisher where Failure == Never {
public static func publisher<P: Publisher>(_ createPublisher: @escaping () -> P) -> Self
where P.Output == Action, P.Failure == Never {
Self(
operation: .publisher(Deferred(createPublisher: createPublisher).eraseToAnyPublisher())
operation: .publisher(
withEscapedDependencies { continuation in
Deferred {
continuation.yield {
createPublisher()
}
}
}
.eraseToAnyPublisher()
)
)
}
}
Expand Down
24 changes: 24 additions & 0 deletions Tests/ComposableArchitectureTests/EffectPublisherTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Combine
import ComposableArchitecture
import XCTest

@MainActor
final class EffectPublisherTests: BaseTCATestCase {
var cancellables: Set<AnyCancellable> = []

func testEscapedDependencies() {
@Dependency(\.date.now) var now

let effect = withDependencies {
$0.date.now = Date(timeIntervalSince1970: 1234567890)
} operation: {
EffectTask.publisher {
Just(now)
}
}

var value: Date?
effect.sink { value = $0 }.store(in: &self.cancellables)
XCTAssertEqual(value, Date(timeIntervalSince1970: 1234567890))
}
}

0 comments on commit 553214e

Please sign in to comment.