Using用法
2019 - 03 - 01
class DisposableResource: Disposable {
var values: [Int]
func dispose() {
self.values = []
}
init(_ values: [Int]) {
self.values = values
}
}
let observable = Observable<Int>.using({ () -> DisposableResource in
return DisposableResource([1, 2, 3])
}, observableFactory: { (resource) -> Observable<Int> in
return Observable<Int>.from(resource.values)
})
observable.debug().subscribe().disposed(by: bag)
// subscribed
// Event next(1)
// Event next(2)
// Event next(3)
// Event completed
// isDisposed