Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncdispatch, asynchttpserver, os, locks
- proc parseRequest(req: Request) {.async.} =
- os.sleep(100)
- await req.respond(Http200, "sdlkfj")
- # TODO remove gcsafe, once Threads are introduced
- proc cb(req: Request) {.async.} =
- # prints only the id of the first started server
- echo getThreadId()
- await parseRequest(req)
- proc start*() =
- # printes different ids
- echo getThreadId()
- let server = newAsyncHttpServer(true, true)
- waitFor server.serve(Port(5000), cb)
- when isMainModule:
- when compileOption("threads"):
- let
- cores: int = countProcessors()
- var
- threads = newSeq[Thread[void]](cores)
- for i in 0 ..< cores:
- createThread[void](threads[i], mas.start)
- joinThreads(threads)
- else:
- echo "compile with threads"
Advertisement
Add Comment
Please, Sign In to add comment