Skip to content

feat: plugin timers (set_timeout / set_interval)#331

Merged
eugenioenko merged 1 commit into
mainfrom
feat/plugin-timers
Jul 4, 2026
Merged

feat: plugin timers (set_timeout / set_interval)#331
eugenioenko merged 1 commit into
mainfrom
feat/plugin-timers

Conversation

@eugenioenko

Copy link
Copy Markdown
Owner

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 — fire fn once after ms
  • ttt.set_interval(ms, fn) -> id — fire fn every ms (floored at 50ms)
  • ttt.clear_timeout(id) / ttt.clear_interval(id) — cancel; interchangeable; unknown id is a no-op

Callbacks dispatch through the existing PostAsync main-loop path (same as exec_async/net.*_async), so they run on the UI thread — plugins can touch state and call any ttt API directly, no goroutine-safety dance. A plugin's timers are all stopped on Destroy (disable, reload, uninstall), so plugins don't need shutdown cleanup.

Tests

  • Unit (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. -race clean.
  • Functional (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 a panel(id) tui helper.
  • Docs: Timers section in the plugin authoring guide; module list updated.

🤖 Generated with Claude Code

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]>
@eugenioenko eugenioenko merged commit fee5932 into main Jul 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant