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 {
|
export {
|
||||||
offload,
|
offload,
|
||||||
handler,
|
handler,
|
||||||
createPooledCallback,
|
|
||||||
createBufferedCallback,
|
|
||||||
OffloadError
|
OffloadError
|
||||||
};
|
};
|
||||||
|
|
2
jsr.json
2
jsr.json
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "@nesterow/offload",
|
"name": "@nesterow/offload",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"exports": "./mod.ts"
|
"exports": "./mod.ts"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
/**
|
||||||
|
* OffloadError class
|
||||||
|
*/
|
||||||
export class OffloadError extends Error {
|
export class OffloadError extends Error {
|
||||||
constructor(message: string, options?: any) {
|
constructor(message: string, options?: any) {
|
||||||
super(message, options);
|
super(message, options);
|
||||||
|
|
|
@ -4,6 +4,9 @@ declare var self: Worker;
|
||||||
|
|
||||||
type HandlerCallback<T, E> = ((data: E) => T) | ((data: E) => Awaited<T>);
|
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> {
|
export async function handler<T, E>(fn: HandlerCallback<T, E>): Promise<void> {
|
||||||
self.addEventListener("message", async (event) => {
|
self.addEventListener("message", async (event) => {
|
||||||
const request = event.data as WorkerRequest<E>;
|
const request = event.data as WorkerRequest<E>;
|
||||||
|
|
|
@ -1,2 +1,8 @@
|
||||||
|
/**
|
||||||
|
* Response from a worker
|
||||||
|
*/
|
||||||
export type WorkerResponse<T> = { id: number; value: T };
|
export type WorkerResponse<T> = { id: number; value: T };
|
||||||
|
/**
|
||||||
|
* Request to a worker
|
||||||
|
*/
|
||||||
export type WorkerRequest<T> = { id: number; params: T };
|
export type WorkerRequest<T> = { id: number; params: T };
|
||||||
|
|
|
@ -82,7 +82,7 @@ function createTaskCallback<T, E>(
|
||||||
return cb;
|
return cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createBufferedCallback<T, E>(
|
function createBufferedCallback<T, E>(
|
||||||
bufSize: number,
|
bufSize: number,
|
||||||
fun: () => TaskCallback<T, E>,
|
fun: () => TaskCallback<T, E>,
|
||||||
): [Callback<T, E>, Terminator] {
|
): [Callback<T, E>, Terminator] {
|
||||||
|
@ -112,7 +112,7 @@ export function createBufferedCallback<T, E>(
|
||||||
return [call, term];
|
return [call, term];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createPooledCallback<T, E>(
|
function createPooledCallback<T, E>(
|
||||||
poolSize: number,
|
poolSize: number,
|
||||||
fun: () => TaskCallback<T, E>,
|
fun: () => TaskCallback<T, E>,
|
||||||
): [Callback<T, E>, Terminator] {
|
): [Callback<T, E>, Terminator] {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@nesterow/offload",
|
"name": "@nesterow/offload",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Anton Nesterov",
|
"name": "Anton Nesterov",
|
||||||
"url": "https://github.com/nesterow"
|
"url": "https://github.com/nesterow"
|
||||||
|
|
Loading…
Reference in a new issue