Skip to content

worker interface

github-actions[bot] edited this page Dec 4, 2023 · 71 revisions

Module: worker-interface

Table of contents

Type Aliases

Functions

Type Aliases

PromiseWorkerType

Ƭ PromiseWorkerType: Object

Type declaration

Name Type
postMessage (message: any, transferables?: Transferable[]) => Promise<any>

Defined in

src/worker-types.ts:26


Transferable

Ƭ Transferable: ArrayBufferLike | ImageBitmap

Transferable

Defined in

src/worker-types.ts:16


WithTransferListFunction

Ƭ WithTransferListFunction: <T>(payload: T, transferList: Transferable[]) => T

Type declaration

▸ <T>(payload, transferList): T

Type parameters
Name
T
Parameters
Name Type
payload T
transferList Transferable[]
Returns

T

Defined in

src/worker-types.ts:24


WorkerInterface

Ƭ WorkerInterface: Object

Type declaration

Name Type
compress { request: { payload: CompressParameters ; type: "compress" } ; result: Awaited<CompressedImage> & { source: Uint8ClampedArray } }
compress.request { payload: CompressParameters ; type: "compress" }
compress.request.payload CompressParameters
compress.request.type "compress"
compress.result Awaited<CompressedImage> & { source: Uint8ClampedArray }

Defined in

src/worker-types.ts:3


WorkerInterfaceImplementation

Ƭ WorkerInterfaceImplementation: { [k in keyof WorkerInterface]: Function }

Defined in

src/worker-types.ts:18


WorkerRequest

Ƭ WorkerRequest: WorkerInterface[keyof WorkerInterface]["request"]

Defined in

src/worker-types.ts:22

Functions

getPromiseWorker

getPromiseWorker(worker): PromiseWorkerType

Wraps a Regular worker into a PromiseWorker

Parameters

Name Type
worker Worker

Returns

PromiseWorkerType

Defined in

src/worker-interface.ts:13


getWorkerInterface

getWorkerInterface(worker): WorkerInterfaceImplementation

Returns an interface where methods of the worker can be called by the host site

Parameters

Name Type
worker PromiseWorkerType

Returns

WorkerInterfaceImplementation

Example

// this assumes a vite-like bundler understands the `?worker` import
import GainMapWorker from '@monogrid/gainmap-js/worker?worker'
import { getPromiseWorker, getWorkerInterface } from '@monogrid/gainmap-js/worker-interface'

// turn our Worker into a PromiseWorker
const promiseWorker = getPromiseWorker(new GainMapWorker())
// get the interface
const workerInterface = getWorkerInterface(promiseWorker)

Defined in

src/worker-interface.ts:33

Clone this wiki locally