UNPKG

@microsoft/windows-admin-center-sdk

Version:

Microsoft - Windows Admin Center Shell

1 lines 1.3 kB
{"version":3,"sources":["../../../packages/core/base/decorators/yield.decorator.ts"],"names":[],"mappings":"AAOA,wBAAgB,KAAK,IAAI,eAAe,CAkBvC","file":"yield.decorator.d.ts","sourcesContent":["/*\r\n * @Yield() Method Decorator\r\n * yields a methods execution to the end of the event loop.\r\n * Note: this only works with functions that return void. The delay makes it impossible to return values in the\r\n * same context as the function was originally executed.\r\n * @returns A @see MethodDecorator for the method that this is decorating\r\n */\r\nexport function Yield(): MethodDecorator {\r\n // eslint-disable-next-line unused-imports/no-unused-vars\r\n return <T>(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\r\n // copy the descriptor\r\n const method = { ...descriptor };\r\n // remember the old value\r\n const value = method.value;\r\n // create a new value that yields using set timeout\r\n method.value = function (...args) {\r\n const instance = this;\r\n // requeue the real method on the end of the event loop.\r\n setTimeout(() => {\r\n value.apply(instance, args);\r\n });\r\n };\r\n\r\n return method;\r\n };\r\n}\r\n"]}