Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package linkmanager
|
|
|
|
import "sync"
|
|
|
|
type establishFlight struct {
|
|
done chan struct{}
|
|
globalGeneration uint64
|
|
keyGeneration uint64
|
|
once sync.Once
|
|
}
|
|
|
|
func (m *Manager[K, M]) joinFlight(key K) (*establishFlight, bool, error) {
|
|
m.mu.Lock()
|
|
if m.closing {
|
|
m.mu.Unlock()
|
|
return nil, false, ErrManagerClosed
|
|
}
|
|
if !m.enabled {
|
|
m.mu.Unlock()
|
|
return nil, false, ErrManagerDisabled
|
|
}
|
|
if flight := m.flights[key]; flight != nil &&
|
|
flight.globalGeneration == m.globalGeneration &&
|
|
flight.keyGeneration == m.keyGenerations[key] {
|
|
m.mu.Unlock()
|
|
return flight, false, nil
|
|
}
|
|
stale := m.flights[key]
|
|
flight := &establishFlight{
|
|
done: make(chan struct{}),
|
|
globalGeneration: m.globalGeneration,
|
|
keyGeneration: m.keyGenerations[key],
|
|
}
|
|
m.flights[key] = flight
|
|
m.mu.Unlock()
|
|
stale.finish()
|
|
return flight, true, nil
|
|
}
|
|
|
|
func (m *Manager[K, M]) finishFlight(key K, flight *establishFlight) {
|
|
m.mu.Lock()
|
|
if m.flights[key] == flight {
|
|
delete(m.flights, key)
|
|
}
|
|
m.mu.Unlock()
|
|
flight.finish()
|
|
}
|
|
|
|
func (flight *establishFlight) finish() {
|
|
if flight == nil {
|
|
return
|
|
}
|
|
flight.once.Do(func() {
|
|
close(flight.done)
|
|
})
|
|
}
|