{
"id": "fn-event-interval",
"dataComponent": "event",
"heading": {
"title": "interval",
"badges": ["Event", "PARTIAL", "Async"]
},
"synopsis": "Schedules a repeating callback that runs every N milliseconds until stopped. Returns a numeric handle used with event:stop.",
"codeBlocks": [
"extend(\"event\")\n\n# Basic usage:\n\nhandle = event:interval(1000, () => {\n slog(\"Tick!\")\n})\n\n# => Logs \"Tick!\" every 1 second.\n# The function returns an integer handle used to stop it:\nevent:stop(handle)\n\n# Partial usage => fix the delay or callback up front.\n\nmyIntervalFunc = ( ) => {\n sput(\"Hello again!\")\n}\n\nsetupEvery2s = event:interval(2000)\n\n# supply the callback now:\nmyHandle = setupEvery2s(myIntervalFunc)\n\n# => calls 'myIntervalFunc' every 2s.\n# To stop it:\nevent:stop(myHandle)\n",
"# Placeholder usage:\n\nmyPartial = event:interval(_, () => {\n slog(\"Fires repeatedly.\")\n})\n\nmyHandle2 = myPartial(300) # => every 300ms\n"
],
"notes": [
"Arguments: (delayMS, callback).",
"- `delayMS`: integer or single-element IntArray specifying the repeat interval in milliseconds.",
"- `callback`: a function with no parameters, called each time the interval elapses.",
"Returns an integer handle. Pass that handle to `event:stop(handle)` to cancel the interval so it no longer fires.",
"If you omit or partial-apply an argument, it returns a partial function needing the missing argument(s).",
"Intervals never stop on their own; you must call `event:stop(handle)` or exit the script."
]
}