From e20130723568cf5e1ca8bcd8319a2d1475b77cf2 Mon Sep 17 00:00:00 2001 From: Huy Doan Date: Mon, 6 Sep 2021 14:33:33 +0700 Subject: [PATCH] mark `readNext()` as {.gcsafe.} in order to use w/ threaded mode --- redis.nimble | 1 + src/redis.nim | 4 ++-- tests/main.nim | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/redis.nimble b/redis.nimble index 8dd3d04..80b18d2 100644 --- a/redis.nimble +++ b/redis.nimble @@ -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" diff --git a/src/redis.nim b/src/redis.nim index 5aa32b0..6610a66 100644 --- a/src/redis.nim +++ b/src/redis.nim @@ -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]) diff --git a/tests/main.nim b/tests/main.nim index d5a265d..979c423 100644 --- a/tests/main.nim +++ b/tests/main.nim @@ -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." @@ -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") @@ -152,4 +154,15 @@ suite "redis async tests": waitFor main() discard waitFor r.flushdb() - waitFor r.quit() \ No newline at end of file + waitFor r.quit() + + +when compileOption("threads"): + proc threadFunc() {.thread.} = + suite "redis threaded tests": + syncTests() + + var th: Thread[void] + createThread(th, threadFunc) + joinThread(th) +