diff --git a/datastore.nimble b/datastore.nimble index 93ec6af..ddc7bed 100644 --- a/datastore.nimble +++ b/datastore.nimble @@ -13,7 +13,7 @@ requires "nim >= 1.2.0", "sqlite3_abi", "stew", "unittest2", - "patty", + "pretty", "threading", "upraises >= 0.1.0 & < 0.2.0" diff --git a/datastore/sharedds.nim b/datastore/sharedds.nim index e7eba27..667c545 100644 --- a/datastore/sharedds.nim +++ b/datastore/sharedds.nim @@ -79,12 +79,13 @@ proc newSharedDataStore*( var self = SharedDatastore() - # res = newThreadResult(ThreadDatastorePtr) - res = cast[ThreadDatastorePtr](allocShared0(sizeof(ThreadDatastorePtr))) + res = newThreadResult(ThreadDatastorePtr) - # res[].signal = ThreadSignalPtr.new().valueOr: - # return failure newException(DatastoreError, "error creating signal") + res[].value = newSharedPtr(ThreadDatastore) + res[].signal = ThreadSignalPtr.new().valueOr: + return failure newException(DatastoreError, "error creating signal") + echo "sds:res: ", res.repr res.createThreadDatastore(backend) # await wait(res[].signal) # res[].signal.close() diff --git a/datastore/threadbackend.nim b/datastore/threadbackend.nim index 680cbeb..27e9314 100644 --- a/datastore/threadbackend.nim +++ b/datastore/threadbackend.nim @@ -48,11 +48,11 @@ type of TestBackend: count*: int - ThreadDatastore = object + ThreadDatastore* = object tp: Taskpool backendDatastore: Datastore - ThreadDatastorePtr* = ptr ThreadDatastore + ThreadDatastorePtr* = SharedPtr[ThreadDatastore] proc newThreadResult*[T](tp: typedesc[T]): TResult[T] = newSharedPtr(ThreadResult[T]) @@ -117,18 +117,18 @@ proc putTask*( # return TResult[void].new() proc createThreadDatastore*( - ret: var ThreadDatastorePtr, + ret: TResult[ThreadDatastorePtr], backend: ThreadBackend, ) = try: echo "createThreadDatastore: start" # var tp = Taskpool.new(num_threads = 2) - ret[].tp = Taskpool.new(num_threads = 2) ##\ + ret[].value[].tp = Taskpool.new(num_threads = 2) ##\ ## Default to one thread, multiple threads \ ## will require more work - echo "ret.tp: ", ret[].tp.repr - ret[].tp.spawn startupDatastore() + echo "ret.tp: ", ret[].repr + ret[].value[].tp.spawn startupDatastore() # ret[].value[].tp.spawn startupDatastore(ret, backend) echo "createThreadDatastore: done"