Skip to content

issues with CurrentValueRelay and PassthroughRelay subscription #157

Open
@reiley-kim

Description

@reiley-kim

1.Relay only sends a finishing event on deallocation.
but using subscribe<R: Relay>(_ 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions