Package Exports
- @rbxts/set-timeout
- @rbxts/set-timeout/out/init.lua
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rbxts/set-timeout) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
⏱️ set-timeout
A simple implementation of setTimeout and setInterval for Roblox TypeScript.
📦 Installation
This package is available for Roblox TypeScript on NPM:
$ npm install @rbxts/set-timeout$ pnpm add @rbxts/set-timeout
📚 Usage
setTimeout(callback, time)
const cleanup = setTimeout(() => {
print("Hello, world!");
}, 1);
cleanup();setInterval(callback, time)
const cleanup = setInterval(() => {
print("Hello, world!");
}, 1);
cleanup();setCountdown(callback, time, interval)
const promise = setCountdown((secondsLeft) => {
print(secondsLeft);
}, 3);
promise.then(() => {
print("Done!");
});
// 3, 2, 1, Done!throttle(callback, time, options)
Creates a throttled function that only invokes callback at most once per every wait seconds.
const throttled = throttle((value: number) => {
print(`Throttled: ${value}`);
}, 1);
for (const index of $range(0, 10)) {
throttled(index);
task.wait(0.25);
}
// Throttled: 0
// Throttled: 4
// Throttled: 8debounce(callback, time, options)
Creates a debounced function that delays invoking callback until after wait seconds have elapsed since the last time the debounced function was invoked.
const debounced = debounce((value: number) => {
print(`Debounced: ${value}`);
}, 1);
for (const index of $range(0, 10)) {
debounced(index);
task.wait(0.25);
}
task.wait(2);
debounced(11);
// Debounced: 10
// Debounced: 11
📝 License
set-timeout is licensed under the MIT License.