mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
672 B
25 lines
672 B
// Returns a blob:// URL which points |
|
// to a javascript file which will call |
|
// importScripts with the given URL |
|
export function getWorkerURL(url: string) { |
|
const content = `importScripts( "${url}" );` |
|
return URL.createObjectURL(new Blob([content], { type: 'text/javascript' })) |
|
} |
|
|
|
export function initWorker(url: string) { |
|
let worker: Worker | null = null |
|
try { |
|
if (/^https?:\/\/'/.test(url)) { |
|
const worker_url = getWorkerURL(url) |
|
worker = new Worker(worker_url) |
|
URL.revokeObjectURL(worker_url) |
|
} else { |
|
worker = new Worker(url, { |
|
type: 'module', |
|
}) |
|
} |
|
} catch (e) { |
|
console.error(e) |
|
} |
|
return worker |
|
}
|
|
|