Skip to content

refactor(message)!: expose spawned task handles - #114

Merged
Kilerd merged 1 commit into
mainfrom
fix/message-task-handles
Sep 14, 2026
Merged

Kilerd merged 1 commit into
mainfrom
fix/message-task-handles

Conversation

@Kilerd

@Kilerd Kilerd commented Sep 14, 2026 •

Copy link
Copy Markdown
Owner

Messager::spawn previously accepted only unit-output messages and discarded Tokio's task handle. It now returns JoinHandle<M::Output>, allowing callers to await values or application errors, observe panics/cancellation through JoinError, and abort work. The implementation returns the handle from the existing tokio::spawn call without adding another task or allocation.

Keep Message / Messager as an optional typed-command convention with application context. Document that send executes in the caller's future, while spawned tasks require caller-managed lifetimes. Update the README, compile-checked API example, runnable message example, and migration guide to match.

Compatibility: calls with a semicolon still compile; code expecting spawn to return () must adapt. Dropping a handle still detaches its task, including when the owning future is cancelled. Spawned messages are not automatically joined by application shutdown; awaiting send inside an owned scheduled execution keeps that work within the scheduler's existing lifetime.

Validation:

  • Four focused regression tests cover result/error and panic propagation, lazy inline execution and cancellation without a runtime, abort-and-join, and detach-on-drop; the existing context test is retained.
  • cargo test -p gotcha and cargo test -p gotcha --all-features (including doctests).
  • cargo check -p message.
  • cargo clippy --all-features --workspace -- -D warnings.
  • RUSTDOCFLAGS='-D warnings' cargo doc -p gotcha --all-features --no-deps.
  • cargo fmt --all --check and git diff --check.

All 11 GitHub CI checks passed for d7bf36f7e84a5086d8b869451507c1b1b5a9cf27.

Closes #96.

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.

[P3][message] 明确 Message/Messager 的职责并评估是否保留为核心封装

1 participant