Page MenuHomePhabricator

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

Authored by kamil on Tue, Mar 7, 9:18 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Mar 22, 3:52 AM
Unknown Object (File)
Wed, Mar 22, 12:30 AM
Unknown Object (File)
Tue, Mar 21, 4:31 AM
Unknown Object (File)
Fri, Mar 17, 5:02 AM
Unknown Object (File)
Wed, Mar 8, 4:25 PM
Unknown Object (File)
Wed, Mar 8, 4:25 PM
Unknown Object (File)
Wed, Mar 8, 11:54 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
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kamil held this revision as a draft.
kamil published this revision for review.Tue, Mar 7, 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 ↗(On Diff #23695)

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.Tue, Mar 14, 3:40 AM