spierce7
03/27/2020, 5:13 AMwithContext
calls.
This means that the wrapper will need to be frozen, and the core class that the wrapper delegates too will need to not be frozen. The wrapper has to have a reference to the core class though. How can I accomplish this? Someone mentioned using a StableRef
, which seems like it will do the job, but then it has to be disposed in order to not cause a memory leak for a reference. That means that a dispose
function has to be added to my wrapper. I’d like to not pollute my interface and require an API like that.
Is there another way?spierce7
03/27/2020, 5:18 AMinternal class ExampleWrapper {
private val delegate = StableRef.create(Example())
suspend fun doSomething(): String = withContext(Platform.dispatcher) {
delegate.get().doSomething()
}
fun dispose() {
delegate.dispose()
}
}
private class Example {
fun doSomething(): String {
// Do something interesting
return "Blah"
}
}
olonho
03/27/2020, 8:38 AMWorker
which manages Example
instances and perform operations via queue. Instance can be referred by an integer handle or map to identify the instance you’re working with, and periodically clean unused instances by storing weak reference to the Wrapper
and removing element if weak ref is zeroed outKris Wong
03/27/2020, 12:47 PMWorker
manage an Example
Kris Wong
03/27/2020, 12:48 PMExample
outside of the Worker
spierce7
03/27/2020, 1:54 PMWorker
frustratingly only allows one event to be processed at a time though. I’m making network requests which could take seconds. There is no reason for that class instance to be inaccessible for potentially seconds. That’s VERY limiting.
Is there a way to remove the queuing restriction from Worker
, or is there another way?spierce7
03/27/2020, 3:30 PMKris Wong
03/27/2020, 3:32 PMfcosta
03/29/2020, 12:21 PMStableRef
in my project with Channels
.