From b2e1d0a133399d87a713c7e29bfd17c6b9363ae0 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Tue, 29 Aug 2023 14:47:22 -0700 Subject: [PATCH] cleanup --- datastore/threadbackend.nim | 4 ++-- datastore/threadproxyds.nim | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/datastore/threadbackend.nim b/datastore/threadbackend.nim index 395d54b..dd590f9 100644 --- a/datastore/threadbackend.nim +++ b/datastore/threadbackend.nim @@ -12,8 +12,6 @@ import ./datastore import ./databuffer import threading/smartptrs -import pretty - export key, query, smartptrs, databuffer push: {.upraises: [].} @@ -58,6 +56,8 @@ proc convert*[T, S](ret: TResult[T], tp: typedesc[S]): Result[S, ref CatchableEr result.ok(ret[].results.get().toSeq(byte)) elif S is string: result.ok(ret[].results.get().toString()) + elif S is void: + result.ok() else: result.ok(ret[].results.get()) else: diff --git a/datastore/threadproxyds.nim b/datastore/threadproxyds.nim index a2395da..158548b 100644 --- a/datastore/threadproxyds.nim +++ b/datastore/threadproxyds.nim @@ -15,8 +15,6 @@ import ./datastore import ./threadbackend import ./fsds -import pretty - export key, query push: {.upraises: [].} @@ -39,7 +37,6 @@ method has*( finally: ret[].signal.close() - # echo "\nSharedDataStore:has:value: ", ret[].repr return ret.convert(bool) method delete*( @@ -56,8 +53,7 @@ method delete*( finally: ret[].signal.close() - # echo "\nSharedDataStore:put:value: ", ret[].repr - return success() + return ret.convert(void) method delete*( self: ThreadProxyDatastore, @@ -74,6 +70,11 @@ method get*( self: ThreadProxyDatastore, key: Key ): Future[?!seq[byte]] {.async.} = + ## implements batch get + ## + ## note: this implementation is rather naive and should + ## probably be switched to use a single ThreadSignal + ## for the entire batch without ret =? newThreadResult(ValueBuffer), err: return failure(err) @@ -84,8 +85,6 @@ method get*( finally: ret[].signal.close() - # print "\nSharedDataStore:put:value: ", ret[] - # let data = ret[].value.toSeq(byte) return ret.convert(seq[byte]) method put*( @@ -103,12 +102,17 @@ method put*( finally: ret[].signal.close() - return success() + return ret.convert(void) method put*( self: ThreadProxyDatastore, batch: seq[BatchEntry] ): Future[?!void] {.async.} = + ## implements batch put + ## + ## note: this implementation is rather naive and should + ## probably be switched to use a single ThreadSignal + ## for the entire batch for entry in batch: if err =? (await self.put(entry.key, entry.data)).errorOption: