I copied the following code from the [asynchttpserver 
documentation](https://nim-lang.org/docs/asynchttpserver.html#shouldAcceptRequest%2CAsyncHttpServer%2Cint)
 to test the new asynchttpserver implementation with the test for accepts or 
not a new request.
    
    
    import asynchttpserver, asyncdispatch
    
    proc main {.async.} =
      var server = newAsyncHttpServer()
      proc cb(req: Request) {.async.} =
        let headers = {"Date": "Tue, 29 Apr 2014 23:40:08 GMT",
            "Content-type": "text/plain; charset=utf-8"}
        await req.respond(Http200, "Hello World", headers.newHttpHeaders())
      
      server.listen Port(8080)
      while true:
        if server.shouldAcceptRequest():
          asyncCheck server.acceptRequest(cb)
        else:
          poll()
    
    asyncCheck main()
    runForever()
    
    
    Run

But when I compile the code and run the program something strange happens. I 
have extremely high CPU and memory usage. It doesn't even show any content in 
the browser. 
    
    
    $ nim c -r test.nim
    $ top
        PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ 
COMMAND
       3523 hdias     20   0 5688212   4.8g   2124 R  99.7  72.7   0:31.90 test
    
    
    Run

What's wrong? Is it a bug? 

Reply via email to