DataHoarder
b8610799c8
All checks were successful
continuous-integration/drone/push Build is passing
38 lines
515 B
Go
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
|
|
}
|