Worker

interface Worker<I, O>(source)

Interface for a Kobweb worker.

This is the API for a worker from the outside-in. That is, it is the view of a worker from the application's point of view, where it submits work to the worker and then waits for a response. (This is in contrast to the WorkerStrategy class, which is the view of a worker from the inside-out).

The Kobweb Worker Gradle plugin implements this interface. See that module (and WorkerProcessor.kt) for more details.

Normally, users are not expected to interact with this interface directly; rather, they should work directly with the generated worker implementation. However, by extracting this interface, we can provide utility methods that work with any worker implementation.

Properties

Link copied to clipboard
abstract var onOutput: WorkerContext.(O) -> Unit

A callback that will be invoked when the worker posts a message communicating finished work.

Functions

Link copied to clipboard
abstract fun postInput(input: I, transferables: Transferables = Transferables.Empty)

Send a message to the worker.

Link copied to clipboard
abstract fun terminate()

Immediately terminate the worker, interrupting any processing it might still be doing.