Skip to content

Commit

Permalink
Use main thread to serve requests
Browse files Browse the repository at this point in the history
prevents blocking and plays more nicely with other async code.
  • Loading branch information
ajusa authored and dom96 committed Oct 29, 2021
1 parent 114f520 commit c8c8611
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/httpbeast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -497,17 +497,15 @@ proc run*(onRequest: OnRequest, settings: Settings) =
echo("Starting ", numThreads, " threads")
if numThreads > 1:
when compileOption("threads"):
var threads = newSeq[Thread[(OnRequest, Settings)]](numThreads)
for i in 0 ..< numThreads:
var threads = newSeq[Thread[(OnRequest, Settings)]](numThreads - 1)
for t in threads.mitems():
createThread[(OnRequest, Settings)](
threads[i], eventLoop, (onRequest, settings)
t, eventLoop, (onRequest, settings)
)
echo("Listening on port ", settings.port) # This line is used in the tester to signal readiness.
joinThreads(threads)
else:
assert false
else:
eventLoop((onRequest, settings))
eventLoop((onRequest, settings))

proc run*(onRequest: OnRequest) {.inline.} =
## Starts the HTTP server with default settings. Calls `onRequest` for each
Expand Down

0 comments on commit c8c8611

Please sign in to comment.