-
Notifications
You must be signed in to change notification settings - Fork 6
Update offscreen.ts #144
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
Update offscreen.ts #144
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,13 +31,7 @@ async function main(): Promise<void> { | |
| ); | ||
|
|
||
| const kernelWorker = await makeKernelWorker(); | ||
| const kernelInit = | ||
| makePromiseKit< | ||
| Extract< | ||
| KernelCommandReply, | ||
| { method: typeof KernelCommandMethod.InitKernel } | ||
| >['params'] | ||
| >(); | ||
| const kernelInitKit = makePromiseKit<void>(); | ||
|
|
||
| /** | ||
| * Reply to a command from the background script. | ||
|
|
@@ -52,15 +46,15 @@ async function main(): Promise<void> { | |
|
|
||
| // Handle messages from the background service worker and the kernel SQLite worker. | ||
| await Promise.all([ | ||
| (async () => { | ||
| kernelWorker.receiveMessages(), | ||
| kernelInitKit.promise.then(async () => { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now we only await the init promise once.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice. |
||
| for await (const message of backgroundStream) { | ||
| await kernelInit.promise; | ||
| isKernelCommand(message) | ||
| ? await kernelWorker.sendMessage(message) | ||
| : logger.debug('Received unexpected message', message); | ||
| } | ||
| })(), | ||
| kernelWorker.receiveMessages(), | ||
| return undefined; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We trigger an ESLint rule without this. |
||
| }), | ||
| ]); | ||
|
|
||
| /** | ||
|
|
@@ -107,11 +101,13 @@ async function main(): Promise<void> { | |
| // involve the user. | ||
| for await (const message of workerStream) { | ||
| if (!isKernelCommandReply(message)) { | ||
| logger.debug('Received unexpected reply', message); | ||
| logger.error('Received unexpected reply', message); | ||
| continue; | ||
|
Comment on lines
+104
to
+105
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this downgrade in preparation for some future change? We never seem to hit this condition on your branch.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's an artifact of a hypothetical era. Since the worker stream is typed and guarded we could just remove this check altogether. |
||
| } | ||
|
|
||
| if (message.method === KernelCommandMethod.InitKernel) { | ||
| logger.debug('Kernel initialized.'); | ||
| kernelInit.resolve(message.params); | ||
| kernelInitKit.resolve(); | ||
| } | ||
| await replyToBackground(message); | ||
| } | ||
|
|
||
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.
Nothing actually used the resolved value of this promise anyway.