This commit is contained in:
Jaremy Creechley 2023-09-19 20:48:59 -07:00
parent 92b6599396
commit 8a36bbbdb2
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
3 changed files with 12 additions and 7 deletions

View File

@ -23,4 +23,6 @@ proc get*[T](self: Datastore2[T], key: KeyBuffer): ?!ValueBuffer {.nimcall.} =
proc put*[T](self: Datastore2[T], key: KeyBuffer, data: ValueBuffer): ?!void {.nimcall.} =
self.put(self.ids, key, data)
proc close*[T](self: Datastore2[T]): ?!void {.nimcall.} =
echo "CLOSE: ", self
echo "CLOSE: ", self.ids.repr
self.close(self.ids)

View File

@ -105,13 +105,13 @@ method put*[T](
await sig.acquireSig()
let ret = newSharedPtr(ThreadResult[void])
proc submitPut(): ?!void =
proc submitPut() =
let bkey = KeyBuffer.new(key)
let bval = DataBuffer.new(data)
# queue taskpool work
self.tds[].tp.spawn putTask(sig, ret, self.tds, bkey, bval)
submitPut().get()
submitPut()
await sig.wait()
return ret.convert(void)
@ -188,7 +188,7 @@ method close*[T](
): Future[?!void] {.async.} =
# TODO: how to handle failed close?
result = success()
? close(self.tds[].ds)
close(self.tds[].ds).get()
if self.tds[].tp != nil:
## this can block... how to handle? maybe just leak?

View File

@ -30,10 +30,10 @@ proc testThreadProxy() =
key1 = Key.init("/a").tryGet
data = "value for 1".toBytes()
teardownAll:
let res = await sds.close()
res.get()
echo "teardown done"
# teardownAll:
# let res = await sds.close()
# res.get()
# echo "teardown done"
test "check put":
# echo "\n\n=== put ==="
@ -52,6 +52,7 @@ proc testThreadProxy() =
for c in res2.get():
val &= char(c)
# print "get res2: ", $val
GC_fullCollect()
proc testThreadProxyBasics() =
suite "Test Basics":
@ -71,6 +72,7 @@ proc testThreadProxyBasics() =
# # print "res3: ", res3
basicStoreTests(sds, key, bytes, otherBytes)
GC_fullCollect()
# proc testThreadProxyQuery() =
# suite "Test Query":
@ -105,6 +107,7 @@ when isMainModule:
for i in 1..100:
testThreadProxy()
testThreadProxyBasics()
GC_fullCollect()
# testThreadProxyQuery()
else:
testThreadProxy()