Thanks @dom96 for the reply.

I wrote this code to test your solution: 
    
    
    import asyncdispatch
    import os
    import threadpool
    
    proc testSync(): bool =
      var count = 0
      while true:
        sleep(1000)
        echo "wakeup sync... ", $count
        count += 1
        if count == 10:
          return true
      return false
    
    proc testAsync(): Future[bool] {.async.} =
      var count = 0
      while true:
        await sleepAsync(1000)
        echo "wakeup async... ", $count
        count += 1
        if count == 10:
          return true
      return false
    
    proc test() {.async.} =
      var messageFlowVar = spawn testSync()
      while true:
        if messageFlowVar.isReady():
          echo "result from testSync"
          break
        sleep(1000)
        echo "wait for the result..."
    
    proc main() {.async.} =
      while true:
        asyncCheck testAsync() # function is never called
        await test()
        echo "continue..."
    
    asyncCheck main()
    
    
    Run

But testAsync function is never called! What is wrong?

Reply via email to