Skip to content

Simplify example to use recommended GetStateChan pattern#38

Merged
robbyt merged 3 commits intomainfrom
claude/simplify-example-pattern-011CUv6rbM63gkgmDjMCaXhy
Nov 8, 2025
Merged

Simplify example to use recommended GetStateChan pattern#38
robbyt merged 3 commits intomainfrom
claude/simplify-example-pattern-011CUv6rbM63gkgmDjMCaXhy

Conversation

@robbyt
Copy link
Owner

@robbyt robbyt commented Nov 8, 2025

Updated example/main.go to use the simpler machine.GetStateChan() pattern instead of manually setting up broadcast.Manager and registering hooks.

This aligns the example with the "Simple Method (Recommended)" approach documented in the README, making it easier for users to understand and follow best practices.

Changes:

  • Removed manual broadcast.Manager creation
  • Removed manual hook registration for broadcasting
  • Use machine.GetStateChan(ctx, stateChan) directly
  • Removed unused broadcast package import

The example now demonstrates the recommended approach for 90% of use cases, while advanced users can still refer to documentation for the manual broadcast.Manager pattern when needed.

Updated example/main.go to use the simpler machine.GetStateChan()
pattern instead of manually setting up broadcast.Manager and
registering hooks.

This aligns the example with the "Simple Method (Recommended)"
approach documented in the README, making it easier for users to
understand and follow best practices.

Changes:
- Removed manual broadcast.Manager creation
- Removed manual hook registration for broadcasting
- Use machine.GetStateChan(ctx, stateChan) directly
- Removed unused broadcast package import

The example now demonstrates the recommended approach for 90% of use
cases, while advanced users can still refer to documentation for the
manual broadcast.Manager pattern when needed.
@github-actions
Copy link

github-actions bot commented Nov 8, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

When using machine.GetStateChan() with a user-created channel, the
broadcast manager does not close the channel on context cancellation
(since it's an external channel). This caused the goroutine to hang
waiting for the channel to close.

Updated the goroutine to watch for context cancellation using a
select statement, ensuring proper cleanup when the context is done.

This fixes the test deadlock in TestRun.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 8, 2025

@robbyt robbyt merged commit 9edb4b9 into main Nov 8, 2025
3 checks passed
@robbyt robbyt deleted the claude/simplify-example-pattern-011CUv6rbM63gkgmDjMCaXhy branch November 8, 2025 20:50
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.

2 participants