Closed HAKASHUN closed 7 years ago
// timeSpanのVariable値 let timeSpan = Variable<RxTimeinterval>(1) // timeSpanを動的にするためのキーとなるObservable let timeSpanObservable: Observable<RxTimeInterval> = timeSpan.asObservable() let countEvents: Observable<[Int]> = Observable.just(timeSpanObservable) .flatMap { timeSpanObservable -> Observable<[Int]> return Observable.create { observer in let disposable = CompositeDisposable() let internalDisposer: Disposable? disposable.addDisposable( timeSpanObservable.subscribeNext { internalDisposer = countEvent .buffer(timeSpan: $0, count: 10, sheduler: MainScheduler.instance) .subscribeNext { observer.onNext($0) } } ) // 破棄される際に、内部のイベントをdisposeする return AnonymousDisposable { internalDisposer?.dispose() disposable.dispose() } } }