Closed Bug 1881522 Opened 1 year ago Closed 1 year ago

Extend PromiseWorker to allow bi-directional communication

Categories

(Toolkit :: Async Tooling, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
125 Branch
Tracking Status
firefox125 --- fixed

People

(Reporter: tarek, Assigned: tarek)

References

Details

Attachments

(1 file)

PromiseWorker is a wrapper around ChromeWorker with extended capabilities designed to simplify main thread-to-worker thread asynchronous function calls.

The problem is that any post from the worker that is not an answer from an initial message from the parent, will break it, as it's based on a queue mechansim see https://searchfox.org/mozilla-central/source/toolkit/components/promiseworker/PromiseWorker.sys.mjs#150

I have a use case where the worker needs to send specific messages back to the parent during the thread-to-worker flow.

e.g.

  1. parent posts a message to run a function into the worker
  2. worker runs some code and needs something from the parent process (in my case fetching a file from cache)
  3. worker eventually sends back the result to the parent

What I propose is to replace the queue with a Map, so when the parent receives a message that is not an answer from https://searchfox.org/mozilla-central/source/toolkit/components/promiseworker/PromiseWorker.sys.mjs#281 -- it still propagates it -- making the PromiseWorker fully bi-directional

Component: Machine Learning → Async Tooling
Product: Core → Toolkit
Blocks: 1881525
Attachment #9382257 - Attachment description: Bug 1881522 - Extend PromiseWorker to allow bi-directional communication r?mossop → Bug 1881522 - Extend PromiseWorker to allow bi-directional communication r?mossop,gregtatum
Pushed by tziade@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/2b49a6a9647f Extend PromiseWorker to allow bi-directional communication r=mossop
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 125 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: