simplifying

This commit is contained in:
Jaremy Creechley 2023-09-25 22:54:58 -07:00
parent 8e573bdfc7
commit cbad3c1396
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300

View File

@ -48,7 +48,6 @@ type
of Sqlite:
sql*: SQLiteBackend[KeyId,DataBuffer]
TaskCtx[D; T: ThreadTypes] = object
key: KeyId
res: ThreadResult[T]
@ -62,11 +61,11 @@ type
semaphore: AsyncSemaphore # semaphore is used for backpressure \
# to avoid exhausting file descriptors
var finishLock: Lock
finishLock.initLock()
var ctxLock: Lock
ctxLock.initLock()
proc setCancelled(ctx: var TaskCtx): bool =
withLock(finishLock):
withLock(ctxLock):
if ctx.running:
return false
else:
@ -110,8 +109,9 @@ proc hasTask[D](ctx: ptr TaskCtx, ds: D) =
try:
let res = has(ds, ctx.key)
ctx.res = res.mapErr() do(e: ref CatchableError) -> ThreadResErr:
e.toThreadErr()
withLock(ctxLock):
ctx.res = res.mapErr() do(e: ref CatchableError) -> ThreadResErr:
e.toThreadErr()
except CatchableError as exc:
trace "Unexpected exception thrown in asyncHasTask", exc = exc.msg
raiseAssert exc.msg