ditto/packages/db/utils/worker.ts
2025-02-16 00:14:41 -06:00

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;
}