Hello world !
Just to tell you that I've published a small package that provides some asynchronous programming features like then and catch for futures.
Feel free to suggest improvements 😉.
How is this:
import std/[asyncdispatch, httpclient]
var
client = newAsyncHttpClient()
f = client.getContent("https://google.com")
f.then do(): echo "Finished with success !"
f.then do(return_value: string): echo return_value
f.catch do(): echo "Failed !"
f.catch do(what_s_wrong: ref Exception): echo what_s_wrong.msg
f.finally do(): echo "Finished !"
Better than this?
import std/[asyncdispatch, httpclient]
proc main {.async.} =
var client = newAsyncHttpClient()
try:
let content = await client.getContent("https://google.com")
echo "Finished with success !"
echo content
except Exception as e:
echo "Failed !"
echo e.msg
finally:
echo "Finished !"
wait_for main()
You basically rewriting language construct, with functions, it's where JS was 10 years ago when await/async weren't available.