我在使用zip运算符时遇到问题。我打算使用可观察的计时器
var timer = Observable<Int>
.interval(0.1, scheduler: MainScheduler.instance)
.do(onNext:
{ num in
if(num == 20)
{
//Purpose of this timer is to show progress if second request takes too long
MessagesManager.show_progress()
}
})
let source = Observable .... //my observable of networking request
return Observable.zip(source, timer,
resultSelector: { value1, value2 in
// Here i want to cancel/dispose/stop timer observable
return value1
})
.do(onNext:
{ item in
MessagesManager.dismiss_progress()
}, onError:
{ error in
MessagesManager.dismiss_progress()
})
我希望zip运算符在第一次调用onComplete时关闭第二个可观察到的值,但是在网络请求完成后计时器继续工作。如何解决此问题,并在zip块中/之后设置可观察到的计时器?
使用take(1)
限制期望的元素数量: