Skip to main content
Version: 0.2.2

clock

import "github.com/Bugs5382/go-saga-orchestration/clock"

Package clock abstracts time so the engine + verbs can be tested without real wall-clock delays. Production uses SystemClock; tests use FakeClock which advances on demand.

type Clockโ€‹

Clock is the abstraction injected into the coordinator + wait verbs.

type Clock interface {
Now() time.Time
// After returns a channel that receives the current time after d
// elapses. FakeClock receives only when Advance(d) is called.
After(d time.Duration) <-chan time.Time
}

type FakeClockโ€‹

FakeClock holds a virtual clock that advances on demand.

type FakeClock struct {
// contains filtered or unexported fields
}

func NewFakeClockโ€‹

func NewFakeClock(start time.Time) *FakeClock

NewFakeClock starts at the given instant (use UTC).

func (*FakeClock) Advanceโ€‹

func (f *FakeClock) Advance(d time.Duration)

Advance moves the clock forward and fires any waiters whose deadline is at or before the new time.

func (*FakeClock) Afterโ€‹

func (f *FakeClock) After(d time.Duration) <-chan time.Time

After registers a waiter that fires only when Advance moves the virtual clock to at or past now+d.

func (*FakeClock) Nowโ€‹

func (f *FakeClock) Now() time.Time

Now returns the current virtual time.

type SystemClockโ€‹

SystemClock delegates to the stdlib time package.

type SystemClock struct{}

func (SystemClock) Afterโ€‹

func (SystemClock) After(d time.Duration) <-chan time.Time

After returns a channel that fires after d elapses, delegating to time.After.

func (SystemClock) Nowโ€‹

func (SystemClock) Now() time.Time

Now returns the current UTC wall-clock time.

Generated by gomarkdoc