Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
支持Run方法
Browse files Browse the repository at this point in the history
  • Loading branch information
CuteReimu committed May 21, 2024
1 parent 3420d6a commit 2f9b481
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions miraihttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ func Connect(host string, port int, channel WsChannel, verifyKey string, qq int6
}
}
}
if b.eventChan == nil {
go fun()
} else {
b.eventChan.Put(fun)
}
b.Run(fun)
}
} else {
b.handlerLock.RUnlock()
Expand Down Expand Up @@ -146,6 +142,15 @@ func (b *Bot) SetLimiter(limiterType string, l *rate.Limiter) {
b.limiter.Store(&limiter{limiterType: limiterType, limiter: l})
}

// Run 如果不是并发方式启动,则此方法会将函数放入事件队列。如果是并发方式启动,则此方法等同于go f()。
func (b *Bot) Run(f func()) {
if b.eventChan == nil {
go f()
} else {
b.eventChan.Put(f)
}
}

// request 发送请求
func (b *Bot) request(command, subCommand string, m any) (gjson.Result, error) {
limiter := b.limiter.Load()
Expand Down

0 comments on commit 2f9b481

Please sign in to comment.