CombineExt provides a collection of operators, publishers and utilities for Combine, that are not provided by Apple themselves, but are common in other Reactive Frameworks and standards.
1.Relay only sends a finishing event on deallocation.
but using subscribe(_ relay: R), the storage subject in the relay received a finishing event.
func testSubscribePublisher() {
var completed = false
relay?
.sink(receiveCompletion: { _ in completed = true },
receiveValue: { self.values.append($0) })
.store(in: &subscriptions)
["1", "2", "3"]
.publisher
.subscribe(relay!)
.store(in: &subscriptions)
XCTAssertFalse(completed)
XCTAssertEqual(values, ["initial", "1", "2", "3"])
// not working, storage subject in the relay is finished
relay!.accept("4")
XCTAssertFalse(completed)
XCTAssertEqual(values, ["initial", "1", "2", "3", "4"])
}
PassthroughRelay doesn’t have an initial value or a buffer of the most recently-published value.
but testSubscribeRelay_CurrentValueToPassthrough test case does not.
func testSubscribeRelay_CurrentValueToPassthrough() {
var completed = false
let input = CurrentValueRelay<String>("initial")
let output = PassthroughRelay<String>()
input
.subscribe(output)
.store(in: &subscriptions)
output
.sink(receiveCompletion: { _ in completed = true },
receiveValue: { self.values.append($0) })
.store(in: &subscriptions)
input.accept("1")
input.accept("2")
input.accept("3")
XCTAssertFalse(completed)
// need to replace with "XCTAssertEqual(values, ["1", "2", "3"])"
XCTAssertEqual(values, ["initial", "1", "2", "3"])
}
1.Relay only sends a finishing event on deallocation. but using subscribe(_ relay: R), the storage subject in the relay received a finishing event.
testSubscribeRelay_CurrentValueToPassthrough
test case does not.153