Class Context#

A context and its pool of inference threads, which anira starts as Wasm Workers; the worker module (options.workerModule) is the one web-only field of a context config. ready() resolves once every Worker is inside its loop.

class Context(abi, context)#

A context (anira_context), the web twin of anira::Context: the core the handlers run on and its pool of inference threads, Wasm Workers on the web. Where the web differs: the options are the context config’s fields in one object (anira::ContextConfig on the C++ side), the worker module is a web-only field, the log is drained by the host (ANIRA_LOG_DRAIN_MANUAL: anira.startLogPump()), the pool’s Workers start with the context and ready() waits for them, since they enter their loops only once the main thread yields, and the context is destroyed with destroy().

Arguments:
  • abi (AniraBindings)

  • context (number)

static create(anira, options={})#
Arguments:
  • anira (WithAbi)

  • options (ContextOptions)

Returns:

Context

numInferenceThreads()#

The size of the core’s inference thread pool (anira_num_inference_threads; the free function anira::num_inference_threads() in C++, a member here, where the module is reached through a context).

Returns:

number

async ready(timeoutMs=10000)#

Resolve once every inference thread of the pool is inside its loop, and at least one: the pool starts with the context, but a Wasm Worker enters its loop only after this thread yields and imports its module first. A context without a pool (threads: 0) resolves once one of the page’s own threads is. Await it before a prepare whose contract warms up (the default: its pass runs on the Workers, else ANIRA_ERROR_INVALID_STATE) and before a render that waits for its inferences (an OfflineAudioContext).

Arguments:
  • timeoutMs (number)

Returns:

Promise<void>

native()#

The anira_context* the raw entries take.

Returns:

number

destroy()#

Destroy the context; the last one stops the pool.