UNPKG

@cheprasov/worker-thread

Version:

The WorkerThread wraps a Web Worker with a Promise, also the class creates a worker script on the fly (without having to create separate worker files). You can 'inline' your worker function in the same js file as main logic.

19 lines (14 loc) 544 B
export const objectUrlMap: Map<string, string> = new Map(); export default class BlobFileFactory { static createJavaScriptObjectUrl(content: string, useCache: boolean = true): string { if (useCache && objectUrlMap.has(content)) { return objectUrlMap.get(content); } const blob = new Blob([content], { type: 'text/javascript' }); const objectUrl = URL.createObjectURL(blob); if (useCache) { objectUrlMap.set(content, objectUrl); } return objectUrl; } }