Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tortmayr committed Jun 3, 2022
1 parent 037f099 commit b2be158
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/common/message-rpc/rpc-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export interface RpcProtocolOptions {

/**
* Establish a RPC protocol on top of a given channel. By default the rpc protocol is bi-directional, meaning it is possible to send
* sends requests and notifications to the remote side (ie. acts as client) as well as receiving requests and notifications from the remote side (i.e. acts as a server).
* requests and notifications to the remote side (i.e. acts as client) as well as receiving requests and notifications from the remote side (i.e. acts as a server).
* Clients can get a promise for a remote request result that will be either resolved or
* rejected depending on the success of the request. Keeps track of outstanding requests and matches replies to the appropriate request
* Currently, there is no timeout handling for long running requests implemented.
* The bi-directional mode can be reconfigured using the {@link RpcProtocolOptions} to construct and RPC protocol instance that acts only as client or server instead.
* The bi-directional mode can be reconfigured using the {@link RpcProtocolOptions} to construct an RPC protocol instance that acts only as client or server instead.
*/
export class RpcProtocol {
static readonly CANCELLATION_TOKEN_KEY = 'add.cancellation.token';
Expand Down
23 changes: 10 additions & 13 deletions packages/plugin-ext/src/hosted/browser/plugin-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,15 @@ export class PluginWorker {
public readonly rpc: RPCProtocol;

constructor() {
const emitter = new Emitter<string>();

this.worker = new Worker(new URL('./worker/worker-main',
// @ts-expect-error (TS1343)
// We compile to CommonJS but `import.meta` is still available in the browser
import.meta.url));

this.worker.onmessage = m => emitter.fire(m.data);
this.worker.onerror = e => console.error(e);

const onCloseEmitter = new Emitter<ChannelCloseEvent>();
const onMessageEmitter = new Emitter<MessageProvider>();
const onErrorEmitter = new Emitter<unknown>();

// eslint-disable-next-line arrow-body-style
this.worker.onmessage = buffer => onMessageEmitter.fire(() => {
return new Uint8ArrayReadBuffer(buffer.data);
});

this.worker.onerror = e => onErrorEmitter.fire(e);
onErrorEmitter.event(e => console.error(e));

this.rpc = new RPCProtocolImpl({
close: () => {
onCloseEmitter.dispose();
Expand All @@ -66,6 +53,16 @@ export class PluginWorker {
onError: onErrorEmitter.event,
onMessage: onMessageEmitter.event
});

// eslint-disable-next-line arrow-body-style
this.worker.onmessage = buffer => onMessageEmitter.fire(() => {
return new Uint8ArrayReadBuffer(buffer.data);
});

this.worker.onmessage = m => onMessageEmitter.fire(m.data);
this.worker.onerror = e => onErrorEmitter.fire(e);

this.worker.onerror = e => console.error(e);
}

}

0 comments on commit b2be158

Please sign in to comment.