mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-17 14:17:28 +08:00
parallel optimization groundwork
This commit is contained in:
@@ -35,7 +35,15 @@ func (mb *MessageBus) PublishInbound(msg InboundMessage) {
|
||||
|
||||
select {
|
||||
case mb.inbound <- msg:
|
||||
case <-time.After(queueWriteTimeout):
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
timer := time.NewTimer(queueWriteTimeout)
|
||||
defer stopAndDrainTimer(timer)
|
||||
select {
|
||||
case mb.inbound <- msg:
|
||||
case <-timer.C:
|
||||
logger.ErrorCF("bus", logger.C0130, map[string]interface{}{
|
||||
logger.FieldChannel: msg.Channel,
|
||||
logger.FieldChatID: msg.ChatID,
|
||||
@@ -62,7 +70,15 @@ func (mb *MessageBus) PublishOutbound(msg OutboundMessage) {
|
||||
|
||||
select {
|
||||
case mb.outbound <- msg:
|
||||
case <-time.After(queueWriteTimeout):
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
timer := time.NewTimer(queueWriteTimeout)
|
||||
defer stopAndDrainTimer(timer)
|
||||
select {
|
||||
case mb.outbound <- msg:
|
||||
case <-timer.C:
|
||||
logger.ErrorCF("bus", logger.C0132, map[string]interface{}{
|
||||
logger.FieldChannel: msg.Channel,
|
||||
logger.FieldChatID: msg.ChatID,
|
||||
@@ -70,6 +86,19 @@ func (mb *MessageBus) PublishOutbound(msg OutboundMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
func stopAndDrainTimer(timer *time.Timer) {
|
||||
if timer == nil {
|
||||
return
|
||||
}
|
||||
if timer.Stop() {
|
||||
return
|
||||
}
|
||||
select {
|
||||
case <-timer.C:
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
func (mb *MessageBus) SubscribeOutbound(ctx context.Context) (OutboundMessage, bool) {
|
||||
select {
|
||||
case msg, ok := <-mb.outbound:
|
||||
|
||||
Reference in New Issue
Block a user