Documentation
¶
Overview ¶
Package clockport provides a minimal time-source port that production code can depend on without coupling to wall-clock behavior. The matching in-memory test fakes (FakeClock) live in github.com/zerodha/kite-mcp-server/testutil — a deliberate split: the production interface stays infrastructure-clean (zero algo2go deps, pure stdlib), while the test fakes stay where Go conventions expect them (a testutil package adjacent to the consumer's tests).
Architectural rationale: Production reverse-deps that previously imported testutil just to reach `testutil.Clock`/`testutil.Ticker`/`testutil.RealClock{}` (e.g., kc/fill_watcher.go in the kite-mcp-server reference consumer) now import this module instead. testutil retains FakeClock + fakeTicker + NewFakeClock (genuinely test-only). The split eliminates the "test helpers used in production paths" misnomer.
What this port does NOT help with:
- Sleeps that wait for external I/O (TCP bind, HTTP server readiness, SQLite worker drain). A fake clock cannot make the OS bind faster; those sleeps stay and belong to integration-test scope.
- Time-based business rules expressed in the domain layer (e.g., order expiry windows, market-hours gates). Those should be wrapped by their own domain-level abstractions if they need fake-clock coverage.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock interface {
// Now returns the current time as perceived by this clock.
Now() time.Time
// NewTicker returns a Ticker that fires at the given interval. Stop
// must be called by the caller to release resources.
NewTicker(d time.Duration) Ticker
}
Clock is the minimal time-source port. The two methods we need today are Now (wall time) and NewTicker (a channel that fires at intervals). Callers who also need Sleep can layer it on top of NewTicker + receive.
type RealClock ¶
type RealClock struct{}
RealClock is the production clock. Zero-value is ready to use; no constructor needed.
type Ticker ¶
type Ticker interface {
// C returns the channel on which ticks are delivered.
C() <-chan time.Time
// Stop stops the ticker. It is safe to call multiple times.
Stop()
}
Ticker abstracts the tick channel + Stop pair. The real implementation wraps *time.Ticker; fake implementations (e.g., github.com/zerodha/kite-mcp-server/testutil.FakeClock's fakeTicker) deliver ticks when their Advance method crosses the interval boundary.