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 API | Replacement |
|---|---|
Top-level runTask | runner.runTask |
Top-level runTaskInBatches | runner.runTasks (independent atomic inputs) |
processOnWorker | runner.runTask with execution: 'worker' |
processOnWorkerInBatches | runner.runTaskInBatches (one streaming processor) |
WorkerObject, TaskDescriptor | Task<Types> |
createWorker, createResourceWorker | initializeTaskWorker(task) |
createWorkerResource | runner.initializeTask |
Resource run, destroy | Handle runTask, close |
Resource dispose hook | Task destroy hook |
WorkerPool, WorkerFarm | Application-owned TaskRunner |
BulkProjectionWorker, projectBulkInWorker | ProjectCoordinatesTask, result {coordinates} |
MapSetupWorker, setupMapInWorker | PrepareMapTask, 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
runTaskInBatchesran independent atomic inputs. Migrate torunner.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 withinitializationOwnership; reusablerunTaskstemplates 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:
autoselects a declared worker, otherwise local processing. It does not inspect input size. ReplacemainThread.maxSize/getSizewith 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 capability | Migration |
|---|---|
| Shared/global worker farm configuration | Own and share an explicit runner in the application |
| Byte budgets, reservations, queue priorities, admission tokens | Bound production before calling the runner; use lazy runTasks inputs for count-bounded work. Implement byte accounting upstream when required |
preloadWorker and automatic worker reuse | Global preloadTasks([task]) loads code only; initializeTask retains a live worker and application state |
| Cooperative worker abort and shared progress counters | Use hard cancellation and onProgress; custom shared-data coordination belongs to the task |
| Built-in job/pool metrics | Measure application timings around calls and use task progress events |
| Shutdown timeouts | Set an application timer that calls terminate; forced stop cannot promise task cleanup |
| Custom transport/protocol extensions | Integrate custom infrastructure outside this API; transport internals are not supported extension points |
| Library-loading helpers | Use 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.