Releases: 0xsequence/runnable
Releases · 0xsequence/runnable
v0.1.0 — adapters subpackage with chi-style middleware + Publisher events
First post-v0.0.x release. Reshapes cross-cutting behavior into a chi-style middleware subpackage and introduces a typed event Publisher so observers can subscribe to adapter events without coupling to the core.
Highlights
- New
runnable/adapterssubpackage providing chi-style middleware constructors that returnrunnable.Adapter(=func(next RunFunc) RunFunc):adapters.Draining(timeout)— graceful shutdown. Outer ctx cancellation triggers drain: work hastimeoutto return viaadapters.Stopping(ctx)before its ctx is force-cancelled andadapters.ErrDrainTimedOutis returned.adapters.Ticker(interval)— periodic execution. Composes withDraining: an in-flight tick is allowed to finish before exit.adapters.Recovering()— converts panics into errors and publishes arunnable.PanicRecoveredEvent.adapters.Retry(maxRetries, resetAfter)— re-invokes on non-context errors; publishes arunnable.RetryEventper failed attempt.
- New core types and Options:
runnable.RunFuncandrunnable.Adapteras the extension point.runnable.WithAdapters(...Adapter)— applies adapters left-to-right (first listed = outermost).
- New observability layer (
runnable.Publisherinterface):runnable.WithPublisher(p)installs a Publisher on the runnable's ctx. Multiple calls fan out viarunnable.Publishers.- Adapters publish typed events:
RetryEvent,DrainStartedEvent,DrainTimedOutEvent,PanicRecoveredEvent. StatusStoreis a Publisher and countsRetryEvents intoStatus.Restarts(replacing the oldWithRetryonStartside-channel).
- NewGroup correctly propagates drain to
Draining-wrapped children — was silently broken when drain was being prototyped on a branch; now correct by construction.
Final shape
r := runnable.New(reconcile, runnable.WithAdapters(
adapters.Draining(10*time.Second),
adapters.Recovering(),
adapters.Retry(3, time.Minute),
adapters.Ticker(2*time.Second),
))Breaking changes from v0.0.3
runnable.WithRetry,runnable.ResetNever→adapters.Retry,adapters.ResetNever.runnable.WithRecoverer→adapters.Recovering()plus arunnable.WithPublishersubscriber listening forrunnable.PanicRecoveredEvent. The two-interfaceRecoveryReporter/StackPrintersplit is gone in favor of a singlePublisher.
Status.Restarts is unchanged from the caller's perspective but is now incremented from RetryEvent rather than an internal onStart callback. No call-site change required when using WithStatus + adapters.Retry.
CI
CI now reads the Go version from go.mod (was pinned to 1.20). actions/checkout@v4 + actions/setup-go@v5.
Compatibility
Go 1.21+ (uses context.WithoutCancel).
Full diff: v0.0.3...v0.1.0
v0.0.3
What's Changed
- recoverer - report panics in runnable functions by @LukasJenicek in #3
New Contributors
- @LukasJenicek made their first contribution in #3
Full Changelog: v0.0.2...v0.0.3