MCPcopy Index your code
hub / github.com/coder/coder / New

Function New

coderd/autobuild/notify/notifier.go:55–78  ·  view source on GitHub ↗

New returns a Notifier that calls cond once every time it polls. - Duplicate values are removed from countdown, and it is sorted in descending order.

(cond Condition, interval time.Duration, countdown []time.Duration, opts ...Option)

Source from the content-addressed store, hash-verified

53// - Duplicate values are removed from countdown, and it is sorted in
54// descending order.
55func New(cond Condition, interval time.Duration, countdown []time.Duration, opts ...Option) *Notifier {
56 // Ensure countdown is sorted in descending order and contains no duplicates.
57 ct := unique(countdown)
58 sort.Slice(ct, func(i, j int) bool {
59 return ct[i] < ct[j]
60 })
61
62 ctx, cancel := context.WithCancel(context.Background())
63 n := &Notifier{
64 ctx: ctx,
65 cancel: cancel,
66 pollDone: make(chan struct{}),
67 countdown: ct,
68 condition: cond,
69 notifiedAt: make(map[time.Duration]bool),
70 clock: quartz.NewReal(),
71 }
72 for _, opt := range opts {
73 opt(n)
74 }
75 go n.poll(interval)
76
77 return n
78}
79
80// poll polls once immediately, and then periodically according to the interval.
81// Poll exits when ticker is closed.

Callers 2

TestNotifierFunction · 0.92
tryPollWorkspaceAutostopFunction · 0.92

Calls 2

pollMethod · 0.95
uniqueFunction · 0.85

Tested by 1

TestNotifierFunction · 0.74