Long polling is old and awkward technology from the turn of the century. I 
recommend using web sockets instead: 
[https://github.com/treeform/ws](https://github.com/treeform/ws)

I think this fixes the issues you had: 
    
    
    import asynchttpserver, asyncdispatch
    
    var server = newAsyncHttpServer()
    var requests: seq[Request]
    
    proc returnAll() {.async.} =
      for req in requests:
        await req.respond(Http200, "Hello World\n")
      requests.setLen(0)
    
    proc cb(req: Request) {.async, gcsafe.} =
      echo req.url.path
      requests.add(req)
      if req.url.path == "/shouldReturn":
        await returnAll()
    
    waitFor server.serve(Port(8080), cb)
    
    
    Run

When I just open [http://localhost:8080](http://localhost:8080)/ in my browser 
it hangs, but when I open 
[http://localhost:8080/shouldReturn](http://localhost:8080/shouldReturn) they 
all return at once.

Reply via email to