mirror of
https://github.com/libp2p/go-openssl.git
synced 2026-08-21 15:13:28 +08:00
Address staticcheck issues
Fix `staticcheck` issues: - S1028 use `fmt.Errorf` to construct formatted errors - ST1017 yoda conditions - ST1005 error message capitalization - ST1006 avoid `self` as receiver name - S1030 use `buf.String` - S1011 avoid redundant loop when `append` suffices - SA4006 unused value - S1019 remove redundant capacity on `make` call - SA2002 `t.Fatal` called outside of test Exported error violates ST1012, which is ignored by this PR since rename may cause breaking changes. Remove redundant parentheses wrapping, and use CamelCase naming while at it.
This commit is contained in:
@@ -45,35 +45,35 @@ func NewFuture() *Future {
|
||||
}
|
||||
|
||||
// Get blocks until the Future has a value set.
|
||||
func (self *Future) Get() (interface{}, error) {
|
||||
self.mutex.Lock()
|
||||
defer self.mutex.Unlock()
|
||||
func (f *Future) Get() (interface{}, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
for {
|
||||
if self.received {
|
||||
return self.val, self.err
|
||||
if f.received {
|
||||
return f.val, f.err
|
||||
}
|
||||
self.cond.Wait()
|
||||
f.cond.Wait()
|
||||
}
|
||||
}
|
||||
|
||||
// Fired returns whether or not a value has been set. If Fired is true, Get
|
||||
// won't block.
|
||||
func (self *Future) Fired() bool {
|
||||
self.mutex.Lock()
|
||||
defer self.mutex.Unlock()
|
||||
return self.received
|
||||
func (f *Future) Fired() bool {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
return f.received
|
||||
}
|
||||
|
||||
// Set provides the value to present and future Get calls. If Set has already
|
||||
// been called, this is a no-op.
|
||||
func (self *Future) Set(val interface{}, err error) {
|
||||
self.mutex.Lock()
|
||||
defer self.mutex.Unlock()
|
||||
if self.received {
|
||||
func (f *Future) Set(val interface{}, err error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
if f.received {
|
||||
return
|
||||
}
|
||||
self.received = true
|
||||
self.val = val
|
||||
self.err = err
|
||||
self.cond.Broadcast()
|
||||
f.received = true
|
||||
f.val = val
|
||||
f.err = err
|
||||
f.cond.Broadcast()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user