Skip to content

Pause Observable #162

Open
Open
@snowtema

Description

@snowtema

Name and description

I have a timer Observable and I need to pause it with one condition: when it'll resume it'll continue to emit elements from an element, which be paused with initial delay.

Example of use

My code:

let timerActiveSubject = BehaviorSubject<Bool>(value: true)
let timer = Observable<Int>
    .timer(0, period: 1, scheduler: MainScheduler.instance)
    .pausable(timerActiveSubject)

timer
    .subscribe(onNext: { (sec) in
        debugPrint("Timer tick: \(sec)")
    })
    .disposed(by: self.bag)

...

timerActiveSubject.onNext(false)

...

// When I send `true` element to subject, timer observable resume, 
//   but emitted all leaved elements in moment without delay. 
timerActiveSubject.onNext(true) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions