MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / Wait

Method Wait

asyncbuffer/cond.go:47–68  ·  view source on GitHub ↗

Wait waits for a Tick() to occur after the given cursor value. Returns the new cursor value when awakened. If the cursor has already advanced beyond the given value, returns immediately with the current cursor.

(cursor uint64)

Source from the content-addressed store, hash-verified

45// Returns the new cursor value when awakened.
46// If the cursor has already advanced beyond the given value, returns immediately with the current cursor.
47func (t *Cond) Wait(cursor uint64) uint64 {
48 t.mu.RLock()
49 ch := t.ch
50 current := t.cursor.Load()
51 t.mu.RUnlock()
52
53 // If cursor already advanced, return immediately
54 if current != cursor || ch == nil {
55 return current
56 }
57
58 // Wait for the channel to close (Tick happened)
59 // If Tick happens after t.mu.RUnlock() and here, we will just wait on a
60 // closed channel and return updated cursor value.
61 <-ch
62
63 // NOTE: Another Tick() could happen here before we read cursor.
64 // This is acceptable - we return the current cursor value, which may be
65 // newer than the Tick() that woke us. The caller will use this cursor
66 // for the next wait cycle and re-check their condition.
67 return t.cursor.Load()
68}
69
70// Close closes the ticker channel and prevents further ticks.
71func (t *Cond) Close() {

Calls 1

LoadMethod · 0.80