mirror of
https://github.com/corda/corda.git
synced 2025-06-21 08:40:03 +00:00
Observable.subscribe().unsubscribe() and ListenableFuture.cancel() (#397)
Observable.subscribe().unsubscribe() dance to free up the MQ resources server-side. * remove an unused import * implement a FlowHandle<Transaction>.finalize method * Rename finalize() to discard() - remove the collection and run discard individually * Remove unused imports * Observable.notUsed helper function * Tweaks to comments * FlowHandle implements AutoClosable * Resolving conflicts and move notUsed to RPC module * Copy Observable.notUsed in core module. * delete discard method
This commit is contained in:
committed by
GitHub
parent
b62f901892
commit
d72b75caa4
19
client/rpc/src/main/kotlin/net/corda/client/rpc/Utils.kt
Normal file
19
client/rpc/src/main/kotlin/net/corda/client/rpc/Utils.kt
Normal file
@ -0,0 +1,19 @@
|
||||
package net.corda.client.rpc
|
||||
|
||||
import rx.Observable
|
||||
|
||||
/**
|
||||
* This function should be invoked on any unwanted Observables returned from RPC to release the server resources.
|
||||
*
|
||||
* subscribe({}, {}) was used instead of simply calling subscribe()
|
||||
* because if an {@code onError} emission arrives (eg. due to an non-correct transaction, such as 'Not sufficient funds')
|
||||
* then {@link OnErrorNotImplementedException} is thrown. As we won't handle exceptions from unused Observables,
|
||||
* empty inputs are used to subscribe({}, {}).
|
||||
*/
|
||||
fun <T> Observable<T>.notUsed() {
|
||||
try {
|
||||
this.subscribe({}, {}).unsubscribe()
|
||||
} catch (e: Exception) {
|
||||
// Swallow any other exceptions as well.
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user