Skip to content

feat(core): timers — send_after / send_every (delayed + periodic messages) - #8

Merged
mash180sx merged 1 commit into
mainfrom
feat/timers
Jul 19, 2026
Merged

feat(core): timers — send_after / send_every (delayed + periodic messages)#8
mash180sx merged 1 commit into
mainfrom
feat/timers

Conversation

@mash180sx

Copy link
Copy Markdown
Contributor

Fills the one clear common-pattern gap: scheduling. Any ActorRef can schedule messages.

API

  • send_after(delay, msg) — one-shot.
  • send_every(interval, make) — periodic; returns a TimerHandle with cancel().
  • Delivery is a non-blocking try_send (best-effort, like pub/sub).

Design (non-invasive)

  • One lazily-started process-global timer thread with a deadline min-heap. Never touches the core hot loop or shutdown.
  • A periodic timer self-terminates when its target actor is gone (try_sendClosed), so a dropped handle never leaks a forever-firing thread.
  • Dropping the handle does not cancel (fire-and-forget just works); cancel() is explicit.
  • Meant for "tick every N ms" / "fire after a delay", not sub-microsecond scheduling.

Docs & example

  • core/examples/timers.rs (heartbeat), guide §4.6 (EN + JA), README example tables (EN + JA).

Verified: build (default + net), tests (incl. 3 new timer tests: fires-after-delay, ticks+cancel, self-terminates-when-gone), doctests, Loom, clippy — all green.

🤖 Generated with Claude Code

…ages)

Fills the one clear common-pattern gap: scheduling. Any ActorRef can schedule messages to itself
or others.

- send_after(delay, msg): one-shot. send_every(interval, make): periodic, returns a TimerHandle
  with cancel(). Delivery is non-blocking try_send (best-effort, like pubsub).
- Implementation: one lazily-started process-global timer thread with a deadline min-heap; never
  touches the core hot loop or shutdown. A periodic timer self-terminates when the target actor is
  gone (try_send Closed), so a dropped handle never leaks a forever-firing thread. Drop does NOT
  cancel — cancel() is explicit — so fire-and-forget just works.
- Example core/examples/timers.rs (heartbeat); guide (EN+JA) §4.6 + README tables (EN+JA).

Verified: build (default+net), tests (incl. 3 new timer tests), doctests, Loom, clippy — all green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mash180sx
mash180sx merged commit 6165ece into main Jul 19, 2026
3 checks passed
@mash180sx
mash180sx deleted the feat/timers branch July 19, 2026 02:00
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