+13
-1
@@ -110,21 +110,33 @@ func (bot *Bot[T]) initLoggers(opts *BotOpts) {
|
||||
|
||||
func (bot *Bot[T]) beginRun() error {
|
||||
bot.runStateMu.Lock()
|
||||
defer bot.runStateMu.Unlock()
|
||||
if bot.running || bot.ran {
|
||||
bot.runStateMu.Unlock()
|
||||
return ErrBotAlreadyRun
|
||||
}
|
||||
bot.running = true
|
||||
bot.ran = true
|
||||
bot.runStateMu.Unlock()
|
||||
if bot.observer != nil {
|
||||
bot.observerAsync = newObserverDispatcher(bot.observer, bot.logger)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bot *Bot[T]) finishRun() {
|
||||
bot.stopObserverDispatcher()
|
||||
bot.runStateMu.Lock()
|
||||
bot.running = false
|
||||
bot.runStateMu.Unlock()
|
||||
}
|
||||
|
||||
func (bot *Bot[T]) stopObserverDispatcher() {
|
||||
if bot.observerAsync == nil {
|
||||
return
|
||||
}
|
||||
bot.observerAsync.close()
|
||||
}
|
||||
|
||||
func nextPollRetryDelay(prev time.Duration) time.Duration {
|
||||
if prev <= 0 {
|
||||
return time.Second
|
||||
|
||||
Reference in New Issue
Block a user