Skip to content

Commit

Permalink
Lazy creation of the DriveContentsProcessor
Browse files Browse the repository at this point in the history
This makes sure to have a working setup with jupyterlite<0.4.0 when
using shared array buffers
  • Loading branch information
martinRenou committed Jun 4, 2024
1 parent d7105d2 commit 24c9cd7
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/web_worker_kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ export class WebWorkerKernel implements IKernel {
this._location = location;
this._kernelspec = kernelspec;
this._contentsManager = contentsManager;
this._contentsProcessor = new DriveContentsProcessor({
contentsManager: this._contentsManager
});
this._sendMessage = sendMessage;
this._worker = new Worker(new URL('./worker.js', import.meta.url), {
type: 'module'
Expand Down Expand Up @@ -183,6 +180,19 @@ export class WebWorkerKernel implements IKernel {
this._remote.processDriveRequest = async <T extends TDriveMethod>(
data: TDriveRequest<T>
) => {
if (!DriveContentsProcessor) {
console.error(
'File system calls over Atomics.wait is only supported with jupyterlite>=0.4.0a3'
);
return;
}

if (this._contentsProcessor === undefined) {
this._contentsProcessor = new DriveContentsProcessor({
contentsManager: this._contentsManager
});
}

return await this._contentsProcessor.processDriveRequest(data);
};
}
Expand Down Expand Up @@ -216,7 +226,7 @@ export class WebWorkerKernel implements IKernel {
private _name: string;
private _location: string;
private _contentsManager: Contents.IManager;
private _contentsProcessor: DriveContentsProcessor;
private _contentsProcessor: DriveContentsProcessor | undefined = undefined;
private _remote: IXeusKernel;
private _isDisposed = false;
private _disposed = new Signal<this, void>(this);
Expand Down

0 comments on commit 24c9cd7

Please sign in to comment.