Sam Schilling
09/27/2019, 9:20 PMval input = ...
val callback: (Result) -> Void = ...
val future = Worker.start().execute(TransferMode.SAFE, { input.freeze() }) {
// do work
result
}
val result = future.result
callback(result)
But obviously that blocks the calling thread until execution is finished.
Open to other suggestions besides Worker
but I am not aware of any other mechanism for multithreading since coroutines only run on main thread.louiscad
09/27/2019, 11:28 PMJeremy
09/28/2019, 12:04 PMfuture.consume { callback(it) }
olonho
09/28/2019, 4:09 PMArkadii Ivanov
09/28/2019, 4:51 PMolonho
09/28/2019, 7:37 PMArkadii Ivanov
09/28/2019, 7:55 PMolonho
09/28/2019, 7:57 PMArkadii Ivanov
09/28/2019, 7:58 PMolonho
09/28/2019, 8:06 PMArkadii Ivanov
09/28/2019, 8:18 PMolonho
09/28/2019, 8:25 PMArkadii Ivanov
09/28/2019, 8:29 PMolonho
09/28/2019, 8:37 PMArkadii Ivanov
09/28/2019, 8:49 PMSam Schilling
10/03/2019, 8:22 PMval callback = { ... } // lambda that mutates global state
val job = { ... } // lambda that is self contained/frozen (detached object graph)
val future = worker.execute(TransferMode.SAFE, { job }) { it() }
// this does not work as it blocks calling thread
future.consume { callback(it) }
// instead I want current thread/context to continue running
// and have callback called once job is complete... however
// seems impossible since I can't pass callback to job as it mutates global state
Sam Schilling
10/03/2019, 8:24 PMexecute
does not block waiting on the completion.Sam Schilling
10/03/2019, 8:26 PMSam Schilling
10/03/2019, 8:27 PM