UtilsService
Learn more about the Utils Service
Introduction
Sometimes you always need the same implementation of a method in different scenarios. For instance, you want to build classes and use them on client and server side.
There are a few helpers built in that should help you to keep your performance in check.
UtilsService can be used on both sides
Available Methods
This section covers all available methods included in UtilsService
setTimeout(listener: CallableFunction, duration: number)
This method creates a simple timeout and automatically clears it once the timeout is finished.
setInterval(listener: CallableFunction, milliseconds: number)
This method creates a simple interval.
Please do not forget to clear the interval if you do not need it anymore
everyTick(listener: CallableFunction)
This method creates a simple everyTick.
Please do not forget to clear the everyTick if you do not need it anymore
autoClearInterval(listener: CallableFunction, milliseconds: number, intervalDuration: number)
This method creates an interval that will automatically be cleared after the defined duration.
nextTick(listener: CallableFunction)
This method creates a simple nextTick.
Please do not forget to clear the nextTick if you do not need it anymore
clearInterval(interval: number)
This method clears an interval based on the intervalId returned by the setInterval method.
clearTimeout(timeout: number)
This method clears a timeout based on the timeoutId.
clearNextTick(tick: number)
This method clears a nextTick based on the nextTickId
clearEveryTick(tick: number)
This method clears a everyTick based on the id returned by the everyTick() method
log(...messages: any[])
This method logs a message
logWarning(...messages: any[])
This method logs a message as a warning
logError(...messages: any[])
This method logs a message as an error
logLoaded(...messages: any[])
This method logs a message formatted as loaded
logUnloaded(...messages: any[])
This method logs a message formatted as unloaded
logRegisteredHandlers(name: string, length: number)
This method is used internal
isProduction(toggle: boolean = false)
Setup the production mode only needed clientside, serverside is setup by .env variable
setCommandPrefix(prefix: string)
Change the prefix for commands, base is /
Event Helpers
All event methods are only called in its specific context - Client/Server. They can't communicate with the other side.
eventOn(eventName: string, listener: (...args: any[]) => void)
Listen for an event
eventOnce(eventName: string, listener: (...args: any[]) => void)
Listen for an event once
eventOff(eventName: string, listener: (...args: any[]) => void)
Removes the listener of an event
Keep in mind that the listener has to be in the same context as the on listener
eventEmit(eventName: string, ...args: any[])
Emits an event
Last updated