diff --git a/datastore/threadbackend.nim b/datastore/threadbackend.nim index 8e10d08..f4d06d8 100644 --- a/datastore/threadbackend.nim +++ b/datastore/threadbackend.nim @@ -193,5 +193,14 @@ proc queryTask*( let qrb = res.toBuffer() ret.success(qrb) - except Exception: - echo "failure" + except Exception as exc: + ret.failure(exc) + + discard ret[].signal.fireSync() + +proc query*( + ret: TResult[QueryResponseBuffer], + tds: ThreadDatastorePtr, + qiter: QueryIterPtr, +) = + tds[].tp.spawn queryTask(ret, tds, qiter) diff --git a/datastore/threadproxyds.nim b/datastore/threadproxyds.nim index ad250eb..f6550ee 100644 --- a/datastore/threadproxyds.nim +++ b/datastore/threadproxyds.nim @@ -139,10 +139,10 @@ method query*( iter[].it = it while not iter[].it.finished: - self.tds[].tp.spawn queryTask(ret, self.tds, iter) + query(ret, self.tds, iter) await wait(ret[].signal) - # iter[].it = nil # ensure our sharedptr doesn't try and dealloc + iter[].it = nil # ensure our sharedptr doesn't try and dealloc finally: ret[].signal.close() @@ -162,7 +162,7 @@ method close*( ## this can block... how to handle? maybe just leak? self.tds[].tp.shutdown() - # self[].tds[].ds = nil # ensure our sharedptr doesn't try and dealloc + self[].tds[].ds = nil # ensure our sharedptr doesn't try and dealloc proc newThreadProxyDatastore*( ds: Datastore,