Commit bf0fe14b authored by xujianhai666's avatar xujianhai666

simplify code

parent 48b91651
...@@ -60,15 +60,13 @@ func (w *waiters) remove(sema *sema) { ...@@ -60,15 +60,13 @@ func (w *waiters) remove(sema *sema) {
if len(*w) == 0 { if len(*w) == 0 {
return return
} }
// build new slice, copy all except sema
ws := *w ws := *w
newWs := make(waiters, 0, len(*w)) for i := range *w {
for i := range ws { if ws[i] == sema {
if ws[i] != sema { *w = append(ws[:i], ws[i+1:]...)
newWs = append(newWs, ws[i]) return
} }
} }
*w = newWs
} }
type items []interface{} type items []interface{}
...@@ -153,9 +151,9 @@ func (q *Queue) Put(items ...interface{}) error { ...@@ -153,9 +151,9 @@ func (q *Queue) Put(items ...interface{}) error {
} }
q.lock.Lock() q.lock.Lock()
defer q.lock.Unlock()
if q.disposed { if q.disposed {
q.lock.Unlock()
return ErrDisposed return ErrDisposed
} }
...@@ -177,7 +175,6 @@ func (q *Queue) Put(items ...interface{}) error { ...@@ -177,7 +175,6 @@ func (q *Queue) Put(items ...interface{}) error {
} }
} }
q.lock.Unlock()
return nil return nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment