UNPKG

@microsoft/windows-admin-center-sdk

Version:

Microsoft - Windows Admin Center Shell

28 lines (26 loc) 1.02 kB
/* * @Delay() Method Decorator * delay 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 Delay(delay = 200) { // 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); }, delay); }; return method; }; } //# sourceMappingURL=delay.decorator.js.map