import { Thread, type ThreadOptions } from '../Thread.ts'; export type ServiceWorkerMessageSource = NonNullable; export interface ThreadServiceWorkerClientsOptions, Exports = Record> extends ThreadOptions { include?(source: ServiceWorkerMessageSource): boolean; } /** * Starts an object within a service worker that will listen for new clients connecting, * and immediately create a thread around each client. You can then call the `get()`, `create()`, * and `delete()` methods to retrieve the threads for a given client. * * @example * import {ThreadServiceWorkerClients} from '@quilted/threads'; * * const threads = new ThreadServiceWorkerClients(); * * addEventListener('message', (event) => { * const source = event.source; * const thread = threads.get(source); * const message = await thread.imports.getMessage(); * }); */ export declare class ThreadServiceWorkerClients, Exports = Record> { #private; /** * Starts a listening for new clients connecting to the service worker, and * creates a thread around each, with the second argument as the exports of the thread. * * @example * ```ts * import {ThreadServiceWorker} from '@quilted/threads'; * * // In your service worker: * * import {ThreadServiceWorkerClients} from '@quilted/threads'; * * ThreadServiceWorkerClients.export({ * async getMessage() { * return 'Hello, world!'; * }, * }); * * // On the main thread: * * const registration = await navigator.serviceWorker.register('worker.js'); * const serviceWorker = registration.installing ?? registration.waiting ?? registration.active; * const {getMessage} = ThreadServiceWorker.import(serviceWorker); * const message = await getMessage(); // 'Hello, world!' * ``` */ static export>(exports: Exports, options?: Omit, Exports>, 'exports'>): void; constructor(options?: ThreadServiceWorkerClientsOptions); get(client: ServiceWorkerMessageSource): Thread | undefined; delete(client: ServiceWorkerMessageSource): boolean; from(client: ServiceWorkerMessageSource, overrideOptions?: ThreadOptions): Thread; export(client: ServiceWorkerMessageSource, exports: Exports, overrideOptions?: Omit, 'exports' | 'imports'>): void; import(client: ServiceWorkerMessageSource, overrideOptions?: Omit, 'exports'>): import("../Thread.ts").ThreadImports; /** @deprecated Use `from()` instead. */ create(client: ServiceWorkerMessageSource, overrideOptions?: ThreadOptions): Thread; } //# sourceMappingURL=ThreadServiceWorkerClients.d.ts.map