mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-05 23:23:10 +00:00
integrate setups
This commit is contained in:
parent
cdb55c0f08
commit
d8d6ad771a
@ -91,25 +91,38 @@ template dispatchTask(self: ThreadDatastore,
|
|||||||
except CancelledError as exc:
|
except CancelledError as exc:
|
||||||
trace "Cancelling thread future!", exc = exc.msg
|
trace "Cancelling thread future!", exc = exc.msg
|
||||||
while not ctx.setCancelled():
|
while not ctx.setCancelled():
|
||||||
|
warn "waiting to cancel thread future!", fn = astToStr(fn), key = $ctx.key
|
||||||
await sleepAsync(10.milliseconds)
|
await sleepAsync(10.milliseconds)
|
||||||
raise exc
|
raise exc
|
||||||
finally:
|
finally:
|
||||||
discard ctx.signal.close()
|
discard ctx.signal.close()
|
||||||
self.semaphore.release()
|
self.semaphore.release()
|
||||||
|
|
||||||
proc hasTask[D](ctx: ptr TaskCtx, ds: D) =
|
proc runTask[D, T](ctx: ptr TaskCtx, ds: D, cb: proc(ctx: ptr TaskCtx): T {.gcsafe.}) {.gcsafe.} =
|
||||||
defer:
|
|
||||||
if not ctx.isNil:
|
|
||||||
discard ctx[].signal.fireSync()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
let res = has(ds, ctx.key)
|
|
||||||
withLock(ctxLock):
|
withLock(ctxLock):
|
||||||
|
if ctx.cancelled:
|
||||||
|
return
|
||||||
|
ctx.running = true
|
||||||
|
|
||||||
|
## run backend command
|
||||||
|
let res = cb(ctx)
|
||||||
|
# let res = has(ds, ctx.key)
|
||||||
|
|
||||||
|
withLock(ctxLock):
|
||||||
|
ctx.running = false
|
||||||
ctx.res = res.mapErr() do(e: ref CatchableError) -> ThreadResErr:
|
ctx.res = res.mapErr() do(e: ref CatchableError) -> ThreadResErr:
|
||||||
e.toThreadErr()
|
e.toThreadErr()
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
trace "Unexpected exception thrown in asyncHasTask", exc = exc.msg
|
trace "Unexpected exception thrown in asyncHasTask", exc = exc.msg
|
||||||
raiseAssert exc.msg
|
raiseAssert exc.msg
|
||||||
|
finally:
|
||||||
|
discard ctx[].signal.fireSync()
|
||||||
|
|
||||||
|
proc hasTask[D](ctx: ptr TaskCtx, ds: D) {.gcsafe.} =
|
||||||
|
## run backend command
|
||||||
|
runTask(ctx, ds) do(ctx: ptr TaskCtx) -> ?!bool:
|
||||||
|
has(ds, ctx.key)
|
||||||
|
|
||||||
method has*(self: ThreadDatastore, key: Key): Future[?!bool] {.async.} =
|
method has*(self: ThreadDatastore, key: Key): Future[?!bool] {.async.} =
|
||||||
var key = KeyId.new key.id()
|
var key = KeyId.new key.id()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user