Motivation
It may be desirable to know whether the worker has already started. As a minimum this could help in testing.
Technical Specification
Consumers would add a method whose sole purpose is to confirm the worker is running, like ping:
epxort const myWorker = {
ping() { return 'pong'; },
...
}
Then, AsyncWorker would have an awaitable method that calls it:
const worker = new Worker(new URL(..., import.meta.url), { type: 'module' });
const wrapper = new AsyncWorker(worker, myWorker);
...
await wrapper.ensureReady(/* maybe with an optional timeout? */);
Internally, AsyncWorker.ensureReady() would simply invoke the myWorker.ping() task and would wait on its work item's promise. The return value would be discarded.
Motivation
It may be desirable to know whether the worker has already started. As a minimum this could help in testing.
Technical Specification
Consumers would add a method whose sole purpose is to confirm the worker is running, like
ping:Then,
AsyncWorkerwould have an awaitable method that calls it:Internally,
AsyncWorker.ensureReady()would simply invoke themyWorker.ping()task and would wait on its work item's promise. The return value would be discarded.