you can also busy poll the result of the spawned proc in an async proc like 
that:
    
    
    import os, asyncdispatch, threadpool
    
    proc doWork(): bool =
       # staff use sql
       echo "starting..."
       sleep(5000)
       
       # complete the future var
       echo "... ok"
       return true
    
    proc asyncWaitFor[T] (work: FlowVar[T], sleepTime: int = 500):Future[T] 
{.async.} =
      ## waits asynchron for a FlowVar to finish
      while not work.isReady :
        await sleepAsync(sleepTime)
      return ^work
    
    proc callWorkAsync() {.async.} =
       let work = spawn doWork()
       discard await asyncWaitFor(work)
    
    
    let call = callWorkAsync()
    echo "do so more"
    waitFor call
    echo "done"
    

Reply via email to