feat: plugin timers (set_timeout / set_interval)#331
Merged
Conversation
ttt.set_timeout(ms, fn) fires once; ttt.set_interval(ms, fn) repeats; both return an id cancelled by clear_timeout/clear_interval (the two are interchangeable). Callbacks dispatch through the PostAsync main-loop path, so they run on the UI thread and can safely touch plugin state and call any ttt API. set_interval is floored at 50ms to avoid starving the loop. All of a plugin's timers are stopped on Destroy (disable, reload, uninstall). Item 3 from the plugin pre-release worklist. Adds a functional-test panel(id) helper. Co-Authored-By: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Item 3 from
pre-release.md(plugin API worklist). Plugins had no way to run periodic work — docker-manager needs a manual Refresh button because of this.API
ttt.set_timeout(ms, fn) -> id— firefnonce aftermsttt.set_interval(ms, fn) -> id— firefneveryms(floored at 50ms)ttt.clear_timeout(id)/ttt.clear_interval(id)— cancel; interchangeable; unknown id is a no-opCallbacks dispatch through the existing
PostAsyncmain-loop path (same asexec_async/net.*_async), so they run on the UI thread — plugins can touch state and call anytttAPI directly, no goroutine-safety dance. A plugin's timers are all stopped onDestroy(disable, reload, uninstall), so plugins don't need shutdown cleanup.Tests
internal/plugin/timers_test.go): timeout-fires-once, interval-repeats-until-cleared, clear-cancels, Destroy-stops-all, distinct ids — via a harness that drains the async queue like the event loop.-raceclean.plugin-timers.test.js): drives the real binary with a--plugin, reads interval ticks + one-shot timeout + a cleared timer out of the OUTPUT panel. Adds apanel(id)tui helper.🤖 Generated with Claude Code