How would one implement long polling in a Nim web server? Basically I would 
like to collect requests in a list and, when some event occurs, return all at 
once.

Non working pseudo code; return all when a client sends the message 
"shouldReturn": 
    
    
    import asynchttpserver, asyncdispatch
    
    var server = newAsyncHttpServer()
    var requests:seq[Request]
    
    proc returnAll() =
        for req in requests:
            await req.respond(Http200, "Hello World\n")
        requests.clear()
    
    proc cb(req: Request) {.async.} =
        requests.add(req)
        if(req.body == "shouldReturn")
            returnAll()
    
    waitFor server.serve(Port(8080), cb)
    
    
    Run

Reply via email to