UNPKG

@microsoft/windows-admin-center-sdk

Version:

Microsoft - Windows Admin Center Shell

28 lines (26 loc) 1.01 kB
/* * @Yield() Method Decorator * yields a methods execution to the end of the event loop. * Note: this only works with functions that return void. The delay makes it impossible to return values in the * same context as the function was originally executed. * @returns A @see MethodDecorator for the method that this is decorating */ export function Yield() { // eslint-disable-next-line unused-imports/no-unused-vars return (target, propertyKey, descriptor) => { // copy the descriptor const method = { ...descriptor }; // remember the old value const value = method.value; // create a new value that yields using set timeout method.value = function (...args) { const instance = this; // requeue the real method on the end of the event loop. setTimeout(() => { value.apply(instance, args); }); }; return method; }; } //# sourceMappingURL=yield.decorator.js.map