execute
fun <T1, T2> execute(
mode: TransferMode,
producer: () -> T1,
job: (T1) -> T2
): Future<T2>
Plan job for further execution in the worker. Execute is a two-phase operation:
- first producer function is executed, and resulting object and whatever it refers to is analyzed for being an isolated object subgraph, if in checked mode.
- Afterwards, this disconnected object graph and job function pointer is being added to jobs queue
of the selected worker. Note that job must not capture any state itself, so that whole state is
explicitly stored in object produced by producer. Scheduled job is being executed by the worker,
and result of such a execution is being disconnected from worker's object graph. Whoever will consume
the future, can use result of worker's computations.
Note, that some technically disjoint subgraphs may lead to
kotlin.IllegalStateException
sokotlin.native.internal.GC.collect()
could be called in the end ofproducer
andjob
if garbage cyclic structures or other uncollected objects refer to the value being transferred.
Return the future with the computation result of job.