mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
优化concurrent模块
This commit is contained in:
@@ -54,16 +54,6 @@ func (c *Concurrent) AsyncDoByQueue(queueId int64, fn func() bool, cb func(err e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c.tasks) > cap(c.tasks) {
|
|
||||||
log.SError("tasks channel is full")
|
|
||||||
if cb != nil {
|
|
||||||
c.pushAsyncDoCallbackEvent(func(err error) {
|
|
||||||
cb(errors.New("tasks channel is full"))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if fn == nil {
|
if fn == nil {
|
||||||
c.pushAsyncDoCallbackEvent(cb)
|
c.pushAsyncDoCallbackEvent(cb)
|
||||||
return
|
return
|
||||||
@@ -75,6 +65,14 @@ func (c *Concurrent) AsyncDoByQueue(queueId int64, fn func() bool, cb func(err e
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case c.tasks <- task{queueId, fn, cb}:
|
case c.tasks <- task{queueId, fn, cb}:
|
||||||
|
default:
|
||||||
|
log.SError("tasks channel is full")
|
||||||
|
if cb != nil {
|
||||||
|
c.pushAsyncDoCallbackEvent(func(err error) {
|
||||||
|
cb(errors.New("tasks channel is full"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user