Skip to content

Add an async method that ensures the worker has started #17

@webJose

Description

@webJose

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions