-
Notifications
You must be signed in to change notification settings - Fork 6
feat(extension): Add a lightweight vat worker service. #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
6af86d7 to
a0bd613
Compare
20174a4 to
4d1014c
Compare
cca8901 to
d146904
Compare
4d1014c to
234f242
Compare
234f242 to
6964fff
Compare
Note: although this move removes all references to @ocap/test-utils from @ocap/extension, the tsconfig entry is maintained because inserting a delay() is useful while developing in the extension.
6964fff to
08c61b6
Compare
08c61b6 to
e0e9195
Compare
sirtimid
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🙂
rekmarks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This enshrines browser APIs (MessagePort, postMessage) within the kernel package. We of course need to have concrete implementations that use these APIs, but the kernel should expect a platform-agnostic interface. This doesn't need to happen in this PR, but I'm requesting changes so we can verify consensus on the matter.
Indeed; what other platforms are we targeting? I'll note that the interface for The friction is that in the browser case we need to make the port on the server end and send it to the client end before wrapping it in a stream, and that this transport is not supported by our |
In the long view, we should be able to drop kernel components into Node.js without issue. For more purposes closer to home, we may well have to use transport mechanisms other than
I agree, my point is merely that only the vat worker service implementations should be aware of this coupling. My concern would be assuaged if we had types (possibly base classes if it makes sense) named |
Alright, I will abstract the interface to a type, relocate the current implementations to I don't think I will attempt an abstract class until we have another implementation case. |
93048fe to
6a83983
Compare
6a83983 to
b3709ae
Compare
rekmarks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with the caveat that when the kernel and worker service client are moved into their own worker, we should use the initializeMessageChannel / receiveMessagePort functions from the streams package. Moreover, establishing the communications channel is perhaps more properly the concern of the offscreen.ts / iframe.ts, and it would be great if we could abstract away the ports from the worker service classes entirely.
| initWorker: ( | ||
| vatId: VatId, | ||
| ) => Promise<DuplexStream<StreamEnvelopeReply, StreamEnvelope>>; | ||
| deleteWorker: (vatId: VatId) => Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't think "init" and "delete" are the right verbs here. "launch" and "terminate" would be more appropriate:
| initWorker: ( | |
| vatId: VatId, | |
| ) => Promise<DuplexStream<StreamEnvelopeReply, StreamEnvelope>>; | |
| deleteWorker: (vatId: VatId) => Promise<void>; | |
| launchWorker: ( | |
| vatId: VatId, | |
| ) => Promise<DuplexStream<StreamEnvelopeReply, StreamEnvelope>>; | |
| terminateWorker: (vatId: VatId) => Promise<void>; |
Arguably, restating "worker" in the method names is also unnecessary:
| initWorker: ( | |
| vatId: VatId, | |
| ) => Promise<DuplexStream<StreamEnvelopeReply, StreamEnvelope>>; | |
| deleteWorker: (vatId: VatId) => Promise<void>; | |
| launch: ( | |
| vatId: VatId, | |
| ) => Promise<DuplexStream<StreamEnvelopeReply, StreamEnvelope>>; | |
| terminate: (vatId: VatId) => Promise<void>; |
I intend that they will communicate with the offscreen document over |
Changes
@ocap/kernelVatWorkertype is relocated to@ocap/extensionas an implementation-specific detail.VatWorkerServiceinterface intended for initializing and deleting vat workers and delivering a connected duplex stream to the kernel.Kernelnow accepts aVatWorkerServicein its constructor, andKernel.launchVatno longer accepts aVatWorker.@ocap/extensionVatWorkertype is relocated from@ocap/utilstovat-worker-service.ts.VatWorker.initnow promises a port and an object instead of a stream pair and an object.VatWorkerServerandVatWorkerClientinoffscreen.tswhich communicate over a message channel. The client will be moved intokernel-worker.tsalong with the kernel in a subsequent PR.@ocap/utils@ocap/extension.