/** Own one regex worker's timeout, cancellation, and cleanup; callers await each request. */
import { Worker, type ResourceLimits } from "node:worker_threads";
import { HashlineError } from "../core/errors.ts";
import { cancellationError, throwIfCancelled } from "./error-text.ts";
import {
restoreWorkerError,
invalidWorkerResult,
type RegexWorkerReply,
} from "./regex-worker-contract.ts";
export async function withRegexWorker(
entry: URL,
decode: (value: unknown) => RegexWorkerReply | undefined,
timeoutMs: number,
signal: AbortSignal | undefined,
execute: (run: (input: Input) => Promise) => Promise