Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issues with CurrentValueRelay and PassthroughRelay subscription #157

Open
reiley-kim opened this issue Apr 15, 2023 · 1 comment
Open

issues with CurrentValueRelay and PassthroughRelay subscription #157

reiley-kim opened this issue Apr 15, 2023 · 1 comment

Comments

@reiley-kim
Copy link

reiley-kim commented Apr 15, 2023

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

@reiley-kim
Copy link
Author

@freak4pc
Please check this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant