MeteorLight/util/request_done.go
DataHoarder b8610799c8
All checks were successful
continuous-integration/drone/push Build is passing
Refactor queue / mount sections and split into multiple files and interfaces
2022-09-03 16:26:45 +02:00

38 lines
515 B
Go

package util
import (
"sync"
"sync/atomic"
)
type RequestDone struct {
done atomic.Bool
lock sync.RWMutex
error error
}
func (r *RequestDone) Done() bool {
return r.done.Load()
}
func (r *RequestDone) Error() error {
r.lock.RLock()
defer r.lock.RUnlock()
return r.error
}
func (r *RequestDone) Complete() {
r.lock.Lock()
defer r.lock.Unlock()
r.done.Store(true)
return
}
func (r *RequestDone) Fail(err error) {
r.lock.Lock()
defer r.lock.Unlock()
r.error = err
r.done.Store(true)
return
}