MeteorLight/util/request_done.go

38 lines
515 B
Go
Raw Permalink Normal View History

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
}