mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-05 16:35:33 +00:00
27 lines
No EOL
884 B
TypeScript
27 lines
No EOL
884 B
TypeScript
namespace com.keyman.text.prediction {
|
|
export class DefaultWorker {
|
|
static constructInstance(): Worker {
|
|
return new Worker(this.asBlobURI(LMLayerWorkerCode));
|
|
}
|
|
|
|
/**
|
|
* Converts the INSIDE of a function into a blob URI that can
|
|
* be passed as a valid URI for a Worker.
|
|
* @param fn Function whose body will be referenced by a URI.
|
|
*
|
|
* This function makes the following possible:
|
|
*
|
|
* let worker = new Worker(LMLayer.asBlobURI(function myWorkerCode () {
|
|
* postMessage('inside Web Worker')
|
|
* function onmessage(event) {
|
|
* // handle message inside Web Worker.
|
|
* }
|
|
* }));
|
|
*/
|
|
static asBlobURI(fn: Function): string {
|
|
let code = LMLayer.unwrap(fn);
|
|
let blob = new Blob([code], { type: 'text/javascript' });
|
|
return URL.createObjectURL(blob);
|
|
}
|
|
}
|
|
} |