-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display wasm module cache status in cockle-config (#92)
* Display wasm module cache status in cockle-config * Linting
- Loading branch information
1 parent
d2062b2
commit e67826f
Showing
8 changed files
with
81 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export class WasmModuleCache { | ||
get(moduleName: string): any { | ||
return this._cache.get(moduleName) ?? undefined; | ||
} | ||
|
||
has(moduleName: string): boolean { | ||
return this._cache.has(moduleName); | ||
} | ||
|
||
set(moduleName: string, module: any): void { | ||
this._cache.set(moduleName, module); | ||
} | ||
|
||
private _cache = new Map<string, any>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
import { WasmModuleCache } from './wasm_module_cache'; | ||
|
||
/** | ||
* Loader of WASM modules. Once loaded, a module is cached so that it is faster to subsequently. | ||
* Must be run in a WebWorker. | ||
*/ | ||
export class WasmLoader { | ||
export class WasmModuleLoader { | ||
constructor(readonly wasmBaseUrl: string) {} | ||
|
||
public getModule(name: string): any { | ||
let module = this._cache.get(name); | ||
let module = this.cache.get(name); | ||
if (module === undefined) { | ||
// Maybe should use @jupyterlab/coreutils.URLExt to combine URL components. | ||
const url = this.wasmBaseUrl + name + '.js'; | ||
console.log('Importing JS/WASM from ' + url); | ||
importScripts(url); | ||
module = (self as any).Module; | ||
this._cache.set(name, module); | ||
this.cache.set(name, module); | ||
} | ||
return module; | ||
} | ||
|
||
private _cache = new Map<string, any>(); | ||
cache = new WasmModuleCache(); | ||
} |