-
Notifications
You must be signed in to change notification settings - Fork 5
worker interface
github-actions[bot] edited this page Dec 4, 2023
·
71 revisions
- PromiseWorkerType
- Transferable
- WithTransferListFunction
- WorkerInterface
- WorkerInterfaceImplementation
- WorkerRequest
Ƭ PromiseWorkerType: Object
Name | Type |
---|---|
postMessage |
(message : any , transferables? : Transferable []) => Promise <any > |
Ƭ Transferable: ArrayBufferLike
| ImageBitmap
Transferable
Ƭ WithTransferListFunction: <T>(payload
: T
, transferList
: Transferable
[]) => T
▸ <T
>(payload
, transferList
): T
Name |
---|
T |
Name | Type |
---|---|
payload |
T |
transferList |
Transferable [] |
T
Ƭ WorkerInterface: Object
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 } |
Ƭ WorkerInterfaceImplementation: { [k in keyof WorkerInterface]: Function }
Ƭ WorkerRequest: WorkerInterface
[keyof WorkerInterface
]["request"
]
▸ getPromiseWorker(worker
): PromiseWorkerType
Wraps a Regular worker into a PromiseWorker
Name | Type |
---|---|
worker |
Worker |
▸ getWorkerInterface(worker
): WorkerInterfaceImplementation
Returns an interface where methods of the worker can be called by the host site
Name | Type |
---|---|
worker |
PromiseWorkerType |
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)