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

Function triggerAsyncFetch

pkg/faviconcache/faviconcache.go:90–123  ·  view source on GitHub ↗

triggerAsyncFetch starts a goroutine to update the favicon cache for the given domain if one isn’t already in progress.

(domain string)

Source from the content-addressed store, hash-verified

88// triggerAsyncFetch starts a goroutine to update the favicon cache
89// for the given domain if one isn’t already in progress.
90func triggerAsyncFetch(domain string) {
91 fetchLock.Lock()
92 if fetching[domain] {
93 // Already fetching this domain; nothing to do.
94 fetchLock.Unlock()
95 return
96 }
97 // Mark this domain as in-flight.
98 fetching[domain] = true
99 fetchLock.Unlock()
100
101 go func() {
102 defer func() {
103 panichandler.PanicHandler("Favicon:triggerAsyncFetch", recover())
104 }()
105
106 // Acquire a slot in the semaphore.
107 fetchSemaphore <- true
108
109 // When done, ensure that we clear the “fetching” flag.
110 defer func() {
111 <-fetchSemaphore
112 fetchLock.Lock()
113 delete(fetching, domain)
114 fetchLock.Unlock()
115 }()
116
117 iconStr, err := fetchFavicon(domain)
118 if err != nil {
119 log.Printf("triggerAsyncFetch: error fetching favicon for %s: %v", domain, err)
120 }
121 SetInCache(domain, FaviconCacheItem{Data: iconStr, LastFetched: time.Now()})
122 }()
123}
124
125func fetchFavicon(domain string) (string, error) {
126 // Create a context that times out after 5 seconds.

Callers 1

GetFaviconFunction · 0.85

Calls 3

PanicHandlerFunction · 0.92
fetchFaviconFunction · 0.85
SetInCacheFunction · 0.85

Tested by

no test coverage detected