MCPcopy
hub / github.com/wavetermdev/waveterm / requestAndWait

Method requestAndWait

pkg/wshrpc/wshremote/processviewer.go:71–99  ·  view source on GitHub ↗

requestAndWait marks the cache as recently requested and returns the current cached result. If the background goroutine is not running it starts it and waits for the first populate before returning.

(ctx context.Context)

Source from the content-addressed store, hash-verified

69// result. If the background goroutine is not running it starts it and waits for the
70// first populate before returning.
71func (s *procCacheState) requestAndWait(ctx context.Context) (*wshrpc.ProcessListResponse, error) {
72 s.lock.Lock()
73 s.lastRequest = time.Now()
74 if !s.running {
75 s.running = true
76 readyCh := make(chan struct{})
77 s.ready = readyCh
78 go s.runLoop(readyCh)
79 }
80 readyCh := s.ready
81 s.lock.Unlock()
82
83 if readyCh != nil {
84 select {
85 case <-readyCh:
86 case <-ctx.Done():
87 return nil, ctx.Err()
88 }
89 }
90
91 s.lock.Lock()
92 result := s.cached
93 s.lock.Unlock()
94
95 if result == nil {
96 return nil, fmt.Errorf("process list unavailable")
97 }
98 return result, nil
99}
100
101func (s *procCacheState) touchLastRequest() {
102 s.lock.Lock()

Callers 1

Calls 2

runLoopMethod · 0.95
ErrMethod · 0.80

Tested by

no test coverage detected