Hi everyone!
I am trying to figure out how to do async, with delegates.
I want to use withTimeout from asyncdispatch module, and for that I need a future.
Now I have a proc that takes an argument, for example,
proc downloadPage(url:string){.async.} = echo url
and I want this to be a delegate, that is, I can choose different procs for this. let f : Future[void] = downloadPage(url) But in this case, it would run immediately. I couldn't find a simple way to create a newFuture(procToRun, arguments)
For this to become a delegate and not run immediately, I wrapped it in a proc(){.async.} = downloadPage(url)
But then I cannot use withTimeout on it, since it's no longer a Future[void]
What am I missing? how to do this?
some sample code:
import asyncdispatch
proc downloadPage(url:string){.async.} = echo url
let url = "someUrl"
let f:Future[void] = proc(){.async.} = waitFor downloadPage(url)
What we do in chronos is the following:
proc downloadPage(url: string) {.async.} = echo url
let f: proc(url: string): Future[void] = downloadPage
waitFor f()
I presume the same thing works with asyncdispatch.