MCPcopy Index your code
hub / github.com/tailscale/tailscale / RunSync

Method RunSync

util/execqueue/execqueue.go:41–58  ·  view source on GitHub ↗

RunSync waits for the queue to be drained and then synchronously runs f. It returns an error if the queue is closed before f is run or ctx expires.

(ctx context.Context, f func())

Source from the content-addressed store, hash-verified

39// RunSync waits for the queue to be drained and then synchronously runs f.
40// It returns an error if the queue is closed before f is run or ctx expires.
41func (q *ExecQueue) RunSync(ctx context.Context, f func()) error {
42 q.mu.Lock()
43 q.initCtxLocked()
44 shutdownCtx := q.ctx
45 q.mu.Unlock()
46
47 ch := make(chan struct{})
48 q.Add(f)
49 q.Add(func() { close(ch) })
50 select {
51 case <-ch:
52 return nil
53 case <-ctx.Done():
54 return ctx.Err()
55 case <-shutdownCtx.Done():
56 return errExecQueueShutdown
57 }
58}
59
60func (q *ExecQueue) run(f func()) {
61 f()

Callers 2

PatchDiscoKeyMethod · 0.80

Calls 6

initCtxLockedMethod · 0.95
AddMethod · 0.95
LockMethod · 0.65
UnlockMethod · 0.65
DoneMethod · 0.65
ErrMethod · 0.45

Tested by 1