a library to speed up the development of Fivem scripts and frameworks
fivem-ts - Documentation v0.7.5 • Docs
fivem-ts - Documentation v0.7.5 / Shared / Cooldown
Cooldown(
milliseconds
): (_target
,propertyKey
,descriptor
) =>void
A decorator that enforces a cooldown period between successive calls to a method.
The @Cooldown
decorator ensures that a method can only be executed once every specified
number of milliseconds. If the method is called again before the cooldown period has elapsed,
a warning is logged, and the method is not executed.
• milliseconds: number
The cooldown period (in milliseconds) that must elapse between method calls.
Function
A function that can be used as a method decorator.
• _target: unknown
• propertyKey: string
• descriptor: PropertyDescriptor
void
class ExampleClass {
@Cooldown(1000) // 1 second cooldown
performAction() {
console.log('Action performed');
}
}
const example = new ExampleClass();
// The first call will execute the method
example.performAction(); // Outputs: Action performed
// Subsequent calls within 1 second will be ignored
example.performAction(); // Outputs: Function performAction is on cooldown.
// After 1 second, the method can be called again
setTimeout(() => example.performAction(), 1000); // Outputs: Action performed