RxSwiftCommunity / RxSwiftExt

A collection of Rx operators & tools not found in the core RxSwift distribution
MIT License
1.33k stars 213 forks source link

takeUntil(_: Completable) #187

Closed Voxar closed 5 years ago

Voxar commented 6 years ago

Hello. I have a suggestion for added overloads to the takeUntil operator

/// take until completable completes or errors out
takeUntil(_: Completable)
/// Like RxSwift.takeUntil(_: Observable) but until other completes.
/// Convenience for `takeUntil(other.ignoreElements())`
takeUntil(completed: Observable)

Example usage

let connection = network.connect(to: host).share()
let heartbeat = connection.flatMapLatest {
    Observable<Int>.interval(10.0, MainScheduler.instance)
    .takeUntil(completed: connection)}
        .withLatestFrom(connection)
    .flatMapLatest(sendHeartbeat)
    .subscribe()
    }

Possible implementation at https://github.com/RxSwiftCommunity/RxSwiftExt/compare/master...Voxar:takeUntilCompleted?expand=1

freak4pc commented 6 years ago

I like it ! Will gladly take a PR even though I’d argue this can even be in the main repo possibly :)

-- Shai Mishali

On October 19, 2018 at 14:01:49, Patrik Sjöberg (notifications@github.com) wrote:

Hello. I have a suggestion for added overloads to the takeUntil operator

/// take until completable completes or errors outtakeUntil(: Completable)/// Like RxSwift.takeUntil(: Observable) but until other completes./// Convenience for takeUntil(other.ignoreElements())takeUntil(completed: Observable)

Example usage

let connection = network.connect(to: host).share()let heartbeat = connection.flatMapLatest { Observable.interval(10.0, MainScheduler.instance) .takeUntil(completed: connection)} .withLatestFrom(connection) .flatMapLatest(sendHeartbeat) .subscribe() }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/RxSwiftCommunity/RxSwiftExt/issues/187, or mute the thread https://github.com/notifications/unsubscribe-auth/AAk7lMLau0fBm-qRi3XqKq5UH8MFttYfks5umbEdgaJpZM4XwJJs .

M0rtyMerr commented 5 years ago

Opened pr to main repo here - https://github.com/ReactiveX/RxSwift/pull/1971 @Voxar approved that I can proceed with his idea

M0rtyMerr commented 5 years ago

@freak4pc what do u think about it? Main won't accept it, should I open PR here? It there any sense in this operator? Overwise, should we close this one?

freak4pc commented 5 years ago

I wanted to use it to begin with but given the discussion that emerged, I think it would cause too much confusion. For a completion it fits more with concat than a takeUntil. Closing for now.