schedulerUtil
A simple utility module for scheduling RunService events with minimal performance impacts and with automatic performance profiling.
Functions
schedule
schedulerUtil.
schedule
(
runServiceEventName:
string
,
callbackIdentifier:
string
,
callback:
(
...any
)
→
(
)
,
maxExpectedCallbackRunTime:
number?
) →
Connection
Schedules the given callback to be run during the given run service event. This is useful because this utility sets up all these events once and registers the given scheduledCallbacksData to be called during each event's invocation point - this prevents you from initializing many different types of RunService events.
schedulerUtil.schedule(schedulerUtil.RunServiceEvent.Stepped, "PerformPhyicsUpdate" function(_, deltaTime: number)
-- Perform physics update here
end)
Yielding is not allowed
Scheduled callbacks should never yield. If they do so, other scheduled callbacks will not be able to run and the utility offers no protection against this due to performance related issues.
Automatic memory & performance profiling
A debug profile is automatically created for the scheduled callback using debug.profilebegin(callbackIdentifier)
,
which will allow you to easily monitor the performance of individual scheduled callback. Additionally, a debug memory
category is also setup for the given callback using debug.setmemorycategory(callbackIdentifier)
.
This utility automatically outputs a warning message in the console every 10 seconds if a given scheduled callback takes a bit too
long to finish running - so you can also pass in an optional 4th argument, maxExpectedCallbackRunTime
to have the system know how long
the given scheduled callback should be expected to finish running.
unschedule
schedulerUtil.
unschedule
(
runServiceEventName:
string
,
callbackIdentifier:
string
) →
(
)
Deschedules the given RunService event bound callback.