MCPcopy
hub / github.com/subquery/subql / mainThreadOnly

Function mainThreadOnly

packages/node-core/src/utils/decorators.ts:8–21  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6
7const logger = getLogger('main');
8export 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}

Callers 6

ProjectServiceClass · 0.90
BlockchainServiceClass · 0.90

Calls 1

warnMethod · 0.45

Tested by

no test coverage detected