I have an `AsyncHTTPClient`. It

1\. Gets content from a server that returns a json formatted string

2\. From that string, my script looks for specific json nodes that describes 
the media the `AsyncHTTPClient` should download. And then the client downloads 
the file.

Now I am using the await keyword in front of the returned string but the 
compiler complains:

> Error: Invalid node kind in 'await', got: nnkVarTy
    
    
    proc main() {.async.}=
      if os.paramCount() < 2:
        quit("Argument required. Usage: $threadgrabber <Thread link> <Relative 
download directory>")
      else:
        var
          boardAndThread = parseBoardAndThread(os.paramStr(1))
          downPath = getCurrentDir() & "/" & os.paramStr(2)
          board = boardAndThread[0]
          thread = boardAndThread[1]
        if not downPath.existsDir():
          echo "Local path not recognized. Using directory: ", downPath
          createDir downPath
        var
          webClient = newAsyncHttpClient()
          link = getAPILink(board, thread)
        await var j: string = getContent(webClient, link)
        for node in parseJson(j)["posts"]:
          if node{"tim"} != nil:
            var
              tim = node["tim"].getInt()
              ext = node["ext"].getStr()
            echo("Downloading ", node.mediaLink(board, thread), " as ", 
fmt"{tim}", "...")
            var downloadFuture = webClient.downloadFile(node.mediaLink(board, 
thread), fmt"{downPath}/{tim}.{ext}")
            downloadFuture.callback=
              proc() =
                echo fmt"Downloading {time}.{ext} Complete"
    
    waitFor main()
    
    
    Run

The main reason I want to use an asynchttpclient is because I want to request 
the client to download multiple files asynchronously. Any pointers? 

Reply via email to