Skip to content

Commit

Permalink
First lint pass
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Nov 30, 2023
1 parent e617482 commit 66a58c4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ console.log(kernel_dir);

// fetch kernel spec for each kernel
const kernel_specs = kernel_dir.map(kernel_dir => {
let spec: any = getPkgJson('kernels/' + kernel_dir + '/kernel.json');
const spec: any = getPkgJson('kernels/' + kernel_dir + '/kernel.json');
spec.name = kernel_dir;
spec.dir = kernel_dir;
spec.resources = {
Expand All @@ -49,7 +49,7 @@ const kernel_specs = kernel_dir.map(kernel_dir => {
console.log(kernel_specs);

const server_kernels = kernel_specs.map(spec => {
let server_kernel: JupyterLiteServerPlugin<void> = {
const server_kernel: JupyterLiteServerPlugin<void> = {
// use name from spec
id: `@jupyterlite/${spec.name}-extension:kernel`,
autoStart: true,
Expand Down
21 changes: 10 additions & 11 deletions src/web_worker_kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@ export class WebWorkerKernel implements IKernel {
*
* @param options The instantiation options for a new WebWorkerKernel
*/
constructor(
options: WebWorkerKernel.IOptions,
spec: any,
) {
const { id, name, sendMessage, location} = options;
constructor(options: WebWorkerKernel.IOptions, spec: any) {
const { id, name, sendMessage, location } = options;
this._id = id;
this._name = name;
this._location = location;
this._spec = spec;
this._sendMessage = sendMessage;
this._worker = new Worker(new URL(`./worker.js`, import.meta.url), {
this._worker = new Worker(new URL('./worker.js', import.meta.url), {
type: 'module'
});

Expand All @@ -48,10 +45,12 @@ export class WebWorkerKernel implements IKernel {
};
this._remote = wrap(this._worker);
this._remote.processMessage({
msg:{header: {
msg_type: 'initialize',
}},
spec : this._spec
msg: {
header: {
msg_type: 'initialize'
}
},
spec: this._spec
});
this.initFileSystem(options);
}
Expand Down Expand Up @@ -215,4 +214,4 @@ export namespace WebWorkerKernel {
export interface IOptions extends IKernel.IOptions {
mountDrive: boolean;
}
}
}
54 changes: 25 additions & 29 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,9 @@ async function get_stdin() {

(self as any).get_stdin = get_stdin;




class XeusKernel {
constructor(resolve: any) {
this._resolve = resolve;

}

async ready(): Promise<void> {
Expand Down Expand Up @@ -141,16 +137,14 @@ class XeusKernel {

async processMessage(event: any): Promise<void> {
const msg_type = event.msg.header.msg_type;
if(msg_type === 'initialize') {

if (msg_type === 'initialize') {
const spec = event.spec;
this._spec = spec;
await this.initialize();

return;
}


await this.ready();

if (
Expand All @@ -163,7 +157,6 @@ class XeusKernel {
globalThis.toplevel_promise = null;
}


if (msg_type === 'input_reply') {
resolveInputReply(event.msg);
} else {
Expand All @@ -188,19 +181,26 @@ class XeusKernel {
}
});
try {

await this.waitRunDependency();
console.log(globalThis.Module);

if(globalThis.Module['async_init'] !== undefined) {
if (globalThis.Module['async_init'] !== undefined) {
console.log('!!!async_init!!!!');
const kernel_root_url=`kernels/${dir}`
const pkg_root_url = `kernel_packages`
console.log("with kernel_root_url", kernel_root_url, "and pkg_root_url", pkg_root_url);
const kernel_root_url = `kernels/${dir}`;
const pkg_root_url = 'kernel_packages';
console.log(
'with kernel_root_url',
kernel_root_url,
'and pkg_root_url',
pkg_root_url
);
const verbose = true;
await globalThis.Module['async_init'](kernel_root_url,pkg_root_url, verbose);
}
else{
await globalThis.Module['async_init'](
kernel_root_url,
pkg_root_url,
verbose
);
} else {
console.log('!!!NO async_init!!!!');
}

Expand All @@ -214,17 +214,15 @@ class XeusKernel {
console.log('!!!start!!!');
this._raw_xkernel.start();
console.log('!!!start-DONE!!!');
}
catch (e) {
if( typeof e === 'number' ) {
const msg = globalThis.Module.get_exception_message(e);
console.error(msg);
throw new Error(msg);
}
else {
console.error(e);
throw(e);
}
} catch (e) {
if (typeof e === 'number') {
const msg = globalThis.Module.get_exception_message(e);
console.error(msg);
throw new Error(msg);
} else {
console.error(e);
throw e;
}
}
this._resolve();
}
Expand Down Expand Up @@ -255,5 +253,3 @@ class XeusKernel {
globalThis.ready = new Promise(resolve => {
expose(new XeusKernel(resolve));
});


0 comments on commit 66a58c4

Please sign in to comment.