* Creates cold [single][Single] that will run a given [block] in a coroutine.
* Every time the returned observable is subscribed, it starts a new coroutine.
* Coroutine returns a single value. Unsubscribing cancels running coroutine.
Feels like as long i subscribes and unsubscribe in the right times it takes care of the coroutine and it doesn't cause memory leaks. Like this:
Copy code
private fun single() = rxSingle {
suspendedFun()
}
Is this correct to assume? I also can't provide a Context with a job to cancel it anyways.
g
gildor
09/25/2019, 8:34 AM
No need to provide Context
gildor
09/25/2019, 8:35 AM
Lifecycle of this single should be managed by subscriber of this Single
gildor
09/25/2019, 8:36 AM
Before 1.3 rxSingle was an extension of coroutine scope, but it was removed, now it’s just top-level function and only subscriber of this single manage lifecycle of it, there is no parent scope (and parent job)
👍 1
g
gmaciel
09/25/2019, 8:55 AM
Yeah exactly, i used before but now i was a bit unsure. Thanks for the answer.