Page MenuHomePhabricator

[web-db] implement proxy for promise-based connection with worker
ClosedPublic

Authored by kamil on Mar 7 2023, 9:18 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Nov 21, 11:59 AM
Unknown Object (File)
Fri, Nov 8, 5:33 AM
Unknown Object (File)
Sat, Nov 2, 2:28 PM
Unknown Object (File)
Sat, Nov 2, 12:14 PM
Unknown Object (File)
Sat, Nov 2, 12:28 AM
Unknown Object (File)
Sat, Nov 2, 12:28 AM
Unknown Object (File)
Sat, Nov 2, 12:28 AM
Unknown Object (File)
Oct 20 2024, 11:00 AM
Subscribers

Details

Summary

Abstraction layer over native event-based communication.

Depends on D6991

Test Plan

Run this code:

const rawWebDbWorker = new SharedWorker('/worker/webDatabase');
const webDBWorker = new WorkerConnectionProxy(
  rawWebDbWorker.port,
  error => {
    console.error(error);
  },
);
const workerResult = await webDBWorker.scheduleOnWorker({
  type: workerRequestMessageTypes.PING,
  text: 'PING',
});
console.log('result: ', workerResult);

const combinedResult = await Promise.all([
  webDBWorker.scheduleOnWorker({
    type: workerRequestMessageTypes.PING,
    text: 'PING',
  }),
  webDBWorker.scheduleOnWorker({
    type: workerRequestMessageTypes.PING,
    text: 'PING',
  }),
  webDBWorker.scheduleOnWorker({
    type: workerRequestMessageTypes.PING,
    text: 'PING',
  }),
  webDBWorker.scheduleOnWorker({
    type: workerRequestMessageTypes.PING,
    text: 'PING',
  }),
]);
console.log(combinedResult);

and check results in browser, desktop, and shared worker consoles.
Also test throwing errors.

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

kamil held this revision as a draft.
kamil published this revision for review.Mar 7 2023, 10:07 AM
web/database/utils/WorkerConnectionProxy.js
39 ↗(On Diff #23510)

Maybe we can include the message (if it exists) in the error so it would be easier to debug.

web/types/worker-types.js
33–34 ↗(On Diff #23510)

In case of an error, the message and id fields don't have to exist (based on the code you wrote)

  • update type
  • add message type to error message
web/database/utils/WorkerConnectionProxy.js
36–45

Each time I tried to reduce indentation, flow complaints about the type in line 47...

web/types/worker-types.js
33–34 ↗(On Diff #23510)

Right, thanks!

This revision is now accepted and ready to land.Mar 14 2023, 3:40 AM