Skip to main content

Migrating to TaskRunner

If your application uses an earlier worker API, start by updating its imports, then choose the runner method that matches how it processes data. New applications can go straight to getting started.

The previous worker entries and top-level task functions have been removed in this breaking update. Applications staying on an older package version are unaffected.

Update the package importโ€‹

Install @math.gl/tasks and replace @math.gl/core/tasks imports with @math.gl/tasks. Core no longer exports the task entry. Provided task catalogs retain their domain imports, such as @math.gl/geospatial/tasks.

Imports from @math.gl/core/worker-utils, @math.gl/geospatial/workers, and @math.gl/geospatial/workers/operations have been removed. Use the replacements below rather than importing private implementation files.

Replace calls and definitionsโ€‹

Removed APIReplacement
Top-level runTaskrunner.runTask
Top-level runTaskInBatchesrunner.runTasks (independent atomic inputs)
processOnWorkerrunner.runTask with execution: 'worker'
processOnWorkerInBatchesrunner.runTaskInBatches (one streaming processor)
WorkerObject, TaskDescriptorTask<Types>
createWorker, createResourceWorkerinitializeTaskWorker(task)
createWorkerResourcerunner.initializeTask
Resource run, destroyHandle runTask, close
Resource dispose hookTask destroy hook
WorkerPool, WorkerFarmApplication-owned TaskRunner
BulkProjectionWorker, projectBulkInWorkerProjectCoordinatesTask, result {coordinates}
MapSetupWorker, setupMapInWorkerPrepareMapTask, input {description}, result {map}

WorkerThread, WorkerJob, WorkerBody, transport message types, URL/version helpers, shared-control helpers, transfer-list utilities, and library/queue helpers are no longer application APIs. Internal transport tests still exercise the underlying implementation. Do not replace removed imports with package deep imports.

TaskOptions, TaskExecution, MainThreadPolicy, worker/resource option types, and pool types are also removed. Use TaskRunOptions<typeof task>, TaskBatchRunOptions<typeof task>, TaskRunsOptions<typeof task>, TaskRunControls, and TaskRunnerOptions as appropriate.

Run a provided taskโ€‹

import {TaskRunner} from '@math.gl/tasks';
import {ProjectCoordinatesTask} from '@math.gl/geospatial/tasks';

const runner = new TaskRunner();
try {
const {coordinates} = await runner.runTask(ProjectCoordinatesTask, {
coordinates: new Float64Array([10, 20]),
projection: {from: 'EPSG:4326', to: 'EPSG:3857'}
});
console.log(coordinates);
} finally {
await runner.close();
}

For custom tasks, wrap bare arrays/scalars in named input and output fields. Application options belong under request.options; move application metadata from the old job context into the input. Execution, ownership, cancellation, and progress stay in the request. A worker target uses {url, capabilities} in Node or {create, capabilities} in a browser; choose one target form.

Behavior changes that need reviewโ€‹

  • Batching: old top-level runTaskInBatches ran independent atomic inputs. Migrate to runner.runTasks, not the similarly named streaming method.
  • Ownership: input copying is now the default. Select inputOwnership: 'transfer' deliberately; all aliases detach. Options and automatic initialization data are copied separately by default. Automatic calls can choose initialization ownership independently with initializationOwnership; reusable runTasks templates allow copy/share only. Shared buffers stay shared.
  • Lifetime: automatic operations release temporary state and workers. Global code preloading does not retain workers or task state. For warm workers or cached projections, explicitly initialize a handle and close it in finally. Handles are serial and occupy runner capacity when idle.
  • Cancellation: worker abort hard-terminates the worker and invalidates its handle. Reinitialize before retrying. There is no rollback or automatic retry. Local code must observe its signal and yield; local cleanup waits for it to settle.
  • Routing: auto selects a declared worker, otherwise local processing. It does not inspect input size. Replace mainThread.maxSize/getSize with an explicit application decision between 'main-thread' and 'worker'.
  • Cleanup: close() drains accepted work; finish or return iterators first. terminate() cancels owned work, including blocked top-level input reads. There is no built-in shutdown deadline.

Intentionally removed advanced controlsโ€‹

These features need application-level replacements; they are not enabled by renaming old options.

Old capabilityMigration
Shared/global worker farm configurationOwn and share an explicit runner in the application
Byte budgets, reservations, queue priorities, admission tokensBound production before calling the runner; use lazy runTasks inputs for count-bounded work. Implement byte accounting upstream when required
preloadWorker and automatic worker reuseGlobal preloadTasks([task]) loads code only; initializeTask retains a live worker and application state
Cooperative worker abort and shared progress countersUse hard cancellation and onProgress; custom shared-data coordination belongs to the task
Built-in job/pool metricsMeasure application timings around calls and use task progress events
Shutdown timeoutsSet an application timer that calls terminate; forced stop cannot promise task cleanup
Custom transport/protocol extensionsIntegrate custom infrastructure outside this API; transport internals are not supported extension points
Library-loading helpersUse standard module imports, fetch, or application-owned loading code

For byte-bounded workloads or cooperative worker cancellation, upgrading requires application changes; the runner does not reproduce these guarantees automatically. See the API reference for supported controls.