142
143
// TrySubmit use mu locking to make it thread safe which has higher latency and not suitable for high throughput
145
>
// Try to acquire lock with timeout to prevent concurrent TrySubmit race condition
146
>
lockCh := make(chan struct{}, 1)
147
>
unlockCh := make(chan struct{})
148
>
go func() {
149
>
s.trySubmitLock.Lock()
150
>
defer s.trySubmitLock.Unlock()
151
>
select {
152
>
case lockCh <- struct{}{}:
153
>
// Successfully notified main goroutine
154
>
<-unlockCh // Wait for signal to unlock
155
case <-unlockCh:
156
// Main goroutine timed out, just unlock and exit