W3cubDocs

/Kotlin

execute

Platform and version requirements: Native (1.3)
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 so kotlin.native.internal.GC.collect() could be called in the end of producer and job if garbage cyclic structures or other uncollected objects refer to the value being transferred.

Return the future with the computation result of job.

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.native.concurrent/-worker/execute.html