Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const config = [
...options,
files: ['**/*.test.{ts,js}'],
})),

{
ignores: [
'yarn.config.cjs',
Expand All @@ -29,6 +30,7 @@ const config = [
'**/coverage',
],
},

{
languageOptions: {
parserOptions: {
Expand All @@ -47,15 +49,15 @@ const config = [
},
],

// This prevents using Node.js and/or browser specific globals. We
// currently use both in our codebase, so this rule is disabled.
'no-restricted-globals': 'off',

'import-x/extensions': 'off',
'import-x/no-unassigned-import': 'off',

// This prevents pretty formatting of comments with multi-line lists entries.
'jsdoc/check-indentation': 'off',

// This prevents using Node.js and/or browser specific globals. We
// currently use both in our codebase, so this rule is disabled.
'no-restricted-globals': 'off',
},
},

Expand Down
22 changes: 9 additions & 13 deletions packages/extension/src/offscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Copy link
Member Author

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.


/**
* Reply to a command from the background script.
Expand All @@ -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 () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we only await the init promise once.

Copy link
Contributor

Choose a reason for hiding this comment

The 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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We trigger an ESLint rule without this.

}),
]);

/**
Expand Down Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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);
}
Expand Down