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

Add toBlocking operator like RxSwift #4

Open
bitomule opened this issue Jul 7, 2019 · 1 comment
Open

Add toBlocking operator like RxSwift #4

bitomule opened this issue Jul 7, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@bitomule
Copy link

bitomule commented Jul 7, 2019

RxSwift includes and useful operator that transform any observable into a blocking sequence.

For Combine it'll be really useful being able to implement the same behavior. Here's how it works on RxSwift http://rx-marin.com/post/rxblocking-part1/

I got something working using current code but it's far from ready, it may help us getting the idea of the expected behavior:

let testScheduler = TestScheduler()

let publisher = TestPublisher<Int, TestError>.init { subscriber in
    subscriber.receive(1)
    subscriber.receive(2)
}

let configuration = TestScheduler.Configuration(pausedOnStart: false, created: 0, subscribed: 0, cancelled: 1, subscriberOptions: TestableSubscriberOptions(initialDemand: Subscribers.Demand.unlimited, subsequentDemand: Subscribers.Demand.unlimited, demandReplenishmentDelay: 0, negativeBalanceHandler: { }))

let testableSubscriber = testScheduler.start(configuration: configuration) { publisher }

XCTAssertEqual(testableSubscriber.sequence, [
    (0, .input(1)),
    (0, .input(2)),
    (0, .subscription),
])

The expected behavior would be:

let publisher = TestPublisher<Int, TestError>.init { subscriber in
    subscriber.receive(1)
    subscriber.receive(2)
}

let blockingPublisher = publisher.toBlocking()

XCTAssertEqual(blockingPublisher.sequence, [1, 2])

This will allow testing Combine publishers in libraries like https://github.com/bitomule/CombineRealm

Here's the RxSwift implementation: https://github.com/ReactiveX/RxSwift/tree/master/RxBlocking

@tcldr tcldr added the enhancement New feature or request label Jul 7, 2019
@Sajjon
Copy link

Sajjon commented Nov 25, 2019

@bitomule @tcldr FYI https://github.com/groue/CombineExpectations

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

No branches or pull requests

3 participants