Skip to content

Commit

Permalink
mark readNext() as {.gcsafe.} in order to use w/ threaded mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ba0f3 committed Sep 6, 2021
1 parent 947e187 commit e201307
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions redis.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ task docs, "Build documentation":

task test, "Run tests":
exec "nim c -r tests/main.nim"
exec "nim c -r --threads:on tests/main.nim"
4 changes: 2 additions & 2 deletions src/redis.nim
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ proc readSingleString(r: Redis | AsyncRedis): Future[RedisString] {.multisync.}
result = res.get(redisNil)
finaliseCommand(r)

proc readNext(r: Redis): RedisList
proc readNext(r: AsyncRedis): Future[RedisList]
proc readNext(r: Redis): RedisList {.gcsafe.}
proc readNext(r: AsyncRedis): Future[RedisList] {.gcsafe.}
proc readArrayLines(r: Redis | AsyncRedis, countLine: string): Future[RedisList] {.multisync.} =
if countLine[0] != '*':
raiseInvalidReply(r, '*', countLine[0])
Expand Down
17 changes: 15 additions & 2 deletions tests/main.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import redis, unittest, asyncdispatch

suite "redis tests":
template syncTests() =
let r = redis.open("localhost")
let keys = r.keys("*")
doAssert keys.len == 0, "Don't want to mess up an existing DB."
Expand Down Expand Up @@ -100,6 +100,8 @@ suite "redis tests":
# delete all keys in the DB at the end of the tests
discard r.flushdb()
r.quit()
suite "redis tests":
syncTests()

suite "redis async tests":
let r = waitFor redis.openAsync("localhost")
Expand Down Expand Up @@ -152,4 +154,15 @@ suite "redis async tests":
waitFor main()

discard waitFor r.flushdb()
waitFor r.quit()
waitFor r.quit()


when compileOption("threads"):
proc threadFunc() {.thread.} =
suite "redis threaded tests":
syncTests()

var th: Thread[void]
createThread(th, threadFunc)
joinThread(th)

0 comments on commit e201307

Please sign in to comment.