Skip to content

Commit

Permalink
Merge pull request #2 from solaoi/fix_sleep-is-not-working-properly
Browse files Browse the repository at this point in the history
fix sleep bug
  • Loading branch information
solaoi authored Dec 13, 2022
2 parents bacc2ac + ec1c3da commit d28aa80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions broly.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.2.1"
version = "0.2.2"
author = "solaoi"
description = "HighPerformance Stub Server"
license = "MIT"
Expand All @@ -10,5 +10,5 @@ bin = @["broly"]

# Dependencies

requires "nim >= 1.6.6"
requires "nim >= 1.6.10"
requires "httpbeast >= 0.4.1"
7 changes: 6 additions & 1 deletion src/broly.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ proc getArgs():tuple[port:int, path:string] =
else:
result.path = key

proc fdSleep(ms: int): Future[void] =
var res = newFuture[void]()
addTimer(ms, true, proc (fd: AsyncFD): bool = res.complete(); return true)
return res

proc onRequest(req: Request): Future[void]{.async.} =
var isSend:bool
{.cast(gcsafe).}:
for v in stubs:
if req.httpMethod == v.stubMethod and req.path == v.stubPath:
try:
if v.stubSleepMs > 0:
await sleepAsync(v.stubSleepMS)
await fdSleep(v.stubSleepMS)
let status = v.stubStatus
if v.stubContentType.isSome:
let headers = v.stubContentType.get
Expand Down

0 comments on commit d28aa80

Please sign in to comment.