ditto/src/utils/worker.ts

9 lines
266 B
TypeScript

/**
* Detect if this thread is running in a Worker context.
*
* https://stackoverflow.com/a/18002694
*/
export function isWorker(): boolean {
// @ts-ignore This is fine.
return typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
}