mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-05 23:23:10 +00:00
docs
This commit is contained in:
parent
25e16f9475
commit
c168c8ea7f
@ -41,6 +41,7 @@ type
|
|||||||
# Filesystem
|
# Filesystem
|
||||||
|
|
||||||
ThreadBackend* = object
|
ThreadBackend* = object
|
||||||
|
## backend case type to avoid needing to make ThreadDatastore generic
|
||||||
case kind*: ThreadBackendKinds
|
case kind*: ThreadBackendKinds
|
||||||
of Sqlite:
|
of Sqlite:
|
||||||
sql*: SQLiteBackend[KeyId,DataBuffer]
|
sql*: SQLiteBackend[KeyId,DataBuffer]
|
||||||
@ -86,6 +87,8 @@ proc acquireSignal(): ?!ThreadSignalPtr =
|
|||||||
success signal.get()
|
success signal.get()
|
||||||
|
|
||||||
template executeTask[T](ctx: TaskCtx[T], blk: untyped) =
|
template executeTask[T](ctx: TaskCtx[T], blk: untyped) =
|
||||||
|
## executes a task on a thread work and handles cleanup after cancels/errors
|
||||||
|
##
|
||||||
try:
|
try:
|
||||||
if not ctx.setRunning():
|
if not ctx.setRunning():
|
||||||
return
|
return
|
||||||
@ -108,7 +111,6 @@ template executeTask[T](ctx: TaskCtx[T], blk: untyped) =
|
|||||||
# ctx[].res.err exc.toThreadErr()
|
# ctx[].res.err exc.toThreadErr()
|
||||||
finally:
|
finally:
|
||||||
ctx.setDone()
|
ctx.setDone()
|
||||||
# echo "\t\texecuteTask:fireSync!"
|
|
||||||
discard ctx[].signal.fireSync()
|
discard ctx[].signal.fireSync()
|
||||||
|
|
||||||
template dispatchTaskWrap[T](self: ThreadDatastore,
|
template dispatchTaskWrap[T](self: ThreadDatastore,
|
||||||
@ -121,13 +123,15 @@ template dispatchTaskWrap[T](self: ThreadDatastore,
|
|||||||
proc runTask() =
|
proc runTask() =
|
||||||
`blk`
|
`blk`
|
||||||
runTask()
|
runTask()
|
||||||
# echo "\t\tdispatchTask:wait!"
|
|
||||||
await wait(ctx[].signal)
|
await wait(ctx[].signal)
|
||||||
|
|
||||||
template dispatchTask[T](self: ThreadDatastore,
|
template dispatchTask[T](self: ThreadDatastore,
|
||||||
signal: ThreadSignalPtr,
|
signal: ThreadSignalPtr,
|
||||||
blk: untyped
|
blk: untyped
|
||||||
): auto =
|
): auto =
|
||||||
|
## handles dispatching a task from an async context
|
||||||
|
## `blk` is the actions, it has `ctx` and `ds` variables in scope.
|
||||||
|
## note that `ds` is a generic
|
||||||
let ctx {.inject.} = newSharedPtr(TaskCtxObj[T](signal: signal))
|
let ctx {.inject.} = newSharedPtr(TaskCtxObj[T](signal: signal))
|
||||||
try:
|
try:
|
||||||
dispatchTaskWrap[T](self, signal, blk)
|
dispatchTaskWrap[T](self, signal, blk)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user