Skip to content

PROTOCOL

Worker

public protocol Worker<Output>: AnyWorkflowConvertible where Rendering == Void

Workers define a unit of asynchronous work.

During a render pass, a workflow can ask the context to await the result of a worker.

When this occurs, the context checks to see if there is already a running worker of the same type. If there is, and if the workers are ‘equivalent’, the context leaves the existing worker running.

If there is not an existing worker of this type, the context will kick off the new worker (via run).

Methods

run()

func run() -> SignalProducer<Output, Never>

Returns a signal producer to execute the work represented by this worker.

isEquivalent(to:)

func isEquivalent(to otherWorker: Self) -> Bool

Returns true if the other worker should be considered equivalent to self. Equivalence should take into account whatever data is meaningful to the task. For example, a worker that loads a user account from a server would not be equivalent to another worker with a different user ID.