When the bot.start() is called twice regardless called consecutively or not - we call the _initializeBot method which in turn sets the RawAPI instance to the fetcher and performs the initial get me request.
The API instance on Fetcher is defined as:
/// Raw API instance.
late final RawAPI api;
And when we try to set the RawAPI instance for the second time (where it was already set) the system comes to crash as final variables cannot be set again.
What changed?
Added two methods, namely pause and resume to the Bot class to pause fetcher temporarily.
Added Bot.pause
Added Bot.resume
Why?
When the bot.stop() is called Televerse actually closes all the related resources - this includes Fetchers (LongPolling / Webhook), the underlying Dio instance (used for making http calls), etc.
So, instead of creating all the related instances once again, it's better to implement a pause/resume feature which can temporarily hold the update streaming.
Being said that Bot.stop now should only be called when you actually want to stop the bot and release all resources.
Fixes #281
What happened?
When the
bot.start()
is called twice regardless called consecutively or not - we call the_initializeBot
method which in turn sets theRawAPI
instance to the fetcher and performs the initial get me request.The API instance on Fetcher is defined as:
And when we try to set the RawAPI instance for the second time (where it was already set) the system comes to crash as final variables cannot be set again.
What changed?
Added two methods, namely
pause
andresume
to the Bot class to pause fetcher temporarily.Bot.pause
Bot.resume
Why?
When the
bot.stop()
is called Televerse actually closes all the related resources - this includes Fetchers (LongPolling
/Webhook
), the underlyingDio
instance (used for making http calls), etc.So, instead of creating all the related instances once again, it's better to implement a pause/resume feature which can temporarily hold the update streaming.
Being said that
Bot.stop
now should only be called when you actually want to stop the bot and release all resources.