reactive-programming

Dispose of Observable Items as they are generated

ぐ巨炮叔叔 提交于 2020-12-08 06:03:35
问题 I have an IObservable that generates items that are disposable, and it will generate a potentially infinite number of them over its lifetime. Because of this, I want to dispose of the last item each time a new item is generated, so the Using operator will not work for this. Is there a different Rx.NET operator that can accomplish this function? 回答1: If you have a IObservable<IDisposable> source then do this to automatically dispose of the previous value and to clean up when the sequence ends:

Dispose of Observable Items as they are generated

隐身守侯 提交于 2020-12-08 06:00:10
问题 I have an IObservable that generates items that are disposable, and it will generate a potentially infinite number of them over its lifetime. Because of this, I want to dispose of the last item each time a new item is generated, so the Using operator will not work for this. Is there a different Rx.NET operator that can accomplish this function? 回答1: If you have a IObservable<IDisposable> source then do this to automatically dispose of the previous value and to clean up when the sequence ends:

How to calculate the average of a Project Reactor Flux?

早过忘川 提交于 2020-11-30 00:11:45
问题 I have a method that returns a Flux<SensorData> , let's suppose SensorData has a field measure: Integer . I would like to calculate the average value of measure of the whole Flux. How can it be done? val sensorFlux: Flux<SensorData> = sensorRepository.findAll() ... 回答1: Mono<Double> average = sensorFlux.collect(Collectors.averagingInt(SensorData::getMeasure)) 回答2: Another way of doing it with an auxiliary object: val average = sensorFlux.map { it.measure } .map { Measure(1, it) } .reduce { t:

.sink is not returning the promise values from a Future Publisher

最后都变了- 提交于 2020-11-29 21:29:50
问题 I have this code in lrvViewModel.swift func getVerificationID (phoneNumber: String) -> Future<String?, Error> { return Future<String?, Error> { promise in PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber, uiDelegate: nil) { (verificationID, error) in if let e = error { promise(.failure(e)) return } print("verification worked") self.defaults.set(verificationID, forKey: "authVerificationID") return promise(.success(verificationID)) } } } and then i call and subscribe to the Publisher

.sink is not returning the promise values from a Future Publisher

岁酱吖の 提交于 2020-11-29 21:27:05
问题 I have this code in lrvViewModel.swift func getVerificationID (phoneNumber: String) -> Future<String?, Error> { return Future<String?, Error> { promise in PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber, uiDelegate: nil) { (verificationID, error) in if let e = error { promise(.failure(e)) return } print("verification worked") self.defaults.set(verificationID, forKey: "authVerificationID") return promise(.success(verificationID)) } } } and then i call and subscribe to the Publisher