mirror of
https://github.com/chrislusf/seaweedfs
synced 2025-07-23 20:12:46 +02:00
* refactor concurrentDownloadLimit * fix loop * fix cmdServer * fix: resolve conversation pr 6920 * Changes logging function (#6919) * updated logging methods for stores * updated logging methods for stores * updated logging methods for filer * updated logging methods for uploader and http_util * updated logging methods for weed server --------- Co-authored-by: akosov <a.kosov@kryptonite.ru> * Improve lock ring (#6921) * fix flaky lock ring test * add more tests * fix: build * fix: rm import util/version * fix: serverOptions * refactoring --------- Co-authored-by: Aleksey Kosov <rusyak777@list.ru> Co-authored-by: akosov <a.kosov@kryptonite.ru> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: chrislu <chris.lu@gmail.com>
32 lines
509 B
Go
32 lines
509 B
Go
package util
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
const HttpStatusCancelled = 499
|
|
|
|
func WaitWithTimeout(ctx context.Context, cond *sync.Cond, timer *time.Timer) int {
|
|
waitDone := make(chan struct{})
|
|
|
|
go func() {
|
|
cond.L.Lock()
|
|
defer cond.L.Unlock()
|
|
cond.Wait()
|
|
defer close(waitDone)
|
|
}()
|
|
|
|
select {
|
|
case <-waitDone:
|
|
return http.StatusOK
|
|
case <-timer.C:
|
|
cond.Broadcast()
|
|
return http.StatusTooManyRequests
|
|
case <-ctx.Done():
|
|
cond.Broadcast()
|
|
return HttpStatusCancelled
|
|
}
|
|
}
|