CombineCommunity / CombineExt

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.
https://combine.community
MIT License
1.72k stars 151 forks source link

issues with CurrentValueRelay and PassthroughRelay subscription #157

Open reiley-kim opened 1 year ago

reiley-kim commented 1 year ago

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"])
    }
  1. 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"])
    }

153

reiley-kim commented 8 months ago

@freak4pc Please check this issue.