()
| 6 | |
| 7 | const logger = getLogger('main'); |
| 8 | export function mainThreadOnly(): MethodDecorator { |
| 9 | return (target, name: string | symbol, descriptor: PropertyDescriptor): void => { |
| 10 | if (!!descriptor && typeof descriptor.value === 'function') { |
| 11 | const orig = descriptor.value; |
| 12 | // tslint:disable no-function-expression no-invalid-this |
| 13 | descriptor.value = function (...args: any[]): any { |
| 14 | if (!isMainThread) { |
| 15 | logger.warn(`${name?.toString()} should only run in main thread`); |
| 16 | } |
| 17 | return orig.bind(this)(...args); |
| 18 | }; |
| 19 | } |
| 20 | }; |
| 21 | } |
no test coverage detected