mirror of
https://github.com/nesterow/offload.git
synced 2024-11-14 14:14:03 +00:00
satisfy export-docs
This commit is contained in:
parent
76541535e4
commit
27ce25096d
2
index.js
2
index.js
|
@ -142,7 +142,5 @@ function withMessageInterceptor(worker) {
|
|||
export {
|
||||
offload,
|
||||
handler,
|
||||
createPooledCallback,
|
||||
createBufferedCallback,
|
||||
OffloadError
|
||||
};
|
||||
|
|
2
jsr.json
2
jsr.json
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "@nesterow/offload",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"exports": "./mod.ts"
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
/**
|
||||
* OffloadError class
|
||||
*/
|
||||
export class OffloadError extends Error {
|
||||
constructor(message: string, options?: any) {
|
||||
super(message, options);
|
||||
|
|
|
@ -4,6 +4,9 @@ declare var self: Worker;
|
|||
|
||||
type HandlerCallback<T, E> = ((data: E) => T) | ((data: E) => Awaited<T>);
|
||||
|
||||
/**
|
||||
* Handler wraps a callback function to be used as a worker handler
|
||||
*/
|
||||
export async function handler<T, E>(fn: HandlerCallback<T, E>): Promise<void> {
|
||||
self.addEventListener("message", async (event) => {
|
||||
const request = event.data as WorkerRequest<E>;
|
||||
|
|
|
@ -1,2 +1,8 @@
|
|||
/**
|
||||
* Response from a worker
|
||||
*/
|
||||
export type WorkerResponse<T> = { id: number; value: T };
|
||||
/**
|
||||
* Request to a worker
|
||||
*/
|
||||
export type WorkerRequest<T> = { id: number; params: T };
|
||||
|
|
|
@ -82,7 +82,7 @@ function createTaskCallback<T, E>(
|
|||
return cb;
|
||||
}
|
||||
|
||||
export function createBufferedCallback<T, E>(
|
||||
function createBufferedCallback<T, E>(
|
||||
bufSize: number,
|
||||
fun: () => TaskCallback<T, E>,
|
||||
): [Callback<T, E>, Terminator] {
|
||||
|
@ -112,7 +112,7 @@ export function createBufferedCallback<T, E>(
|
|||
return [call, term];
|
||||
}
|
||||
|
||||
export function createPooledCallback<T, E>(
|
||||
function createPooledCallback<T, E>(
|
||||
poolSize: number,
|
||||
fun: () => TaskCallback<T, E>,
|
||||
): [Callback<T, E>, Terminator] {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@nesterow/offload",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"author": {
|
||||
"name": "Anton Nesterov",
|
||||
"url": "https://github.com/nesterow"
|
||||
|
|
Loading…
Reference in a new issue