Async update handlers
Closed this issue · 5 comments
Hey / Hi, can you please allow async update handlers ?
As of now I need to write this:
startBot { defaultConfig with Token = "token" } (onUpdate >> Async.RunSynchronously) Option.None
It would be very cool if you made it also work with functions returning Async<'t>
Hi. You can use Async.Start
instead Async.RunSynchronously
Ok, but is it gonna be like a fire-and-forget function then?
I don't want it to be fire-and-forget because I want to make sure all errors are handled etc etc
Or I don't need to worry about it?
You should handle all errors in update function by yourself. Otherwise, the bot will crash with the exception
But here I've found a code that handles internal errors by printing their details in console:
Funogram/src/Funogram.Telegram/Bot.fs
Line 81 in 1115081
Or you mean that it's not gonna work with Async.Start i.e it will crash if an exception is thrown on a background thread?
Also I've found a code that seems to be pretty easy to be adjusted to async update handlers:
Funogram/src/Funogram.Telegram/Bot.fs
Line 73 in 1115081
I guess simply changing that to do! would do the trick, wouldn't it (just curious)?
I'm sorry for late reply.
But here I've found a code that handles internal errors by printing their details in console:
I've changed this behavior in 2.0.3 version. At this moment you can configure error handler with OnError
field in config.
Let me explain Funogram's idea. Funogram have basic Telegram types and server-interaction code and this enough to build any bots you want. But we also have Funogram.Bot
module to allow developers write bots as quickly as possible and do not think about fetching updates, parsing commands etc. So I think that in most cases developers do not want to wait when command will fully processed before fetch new updates.