mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-08 00:13:08 +00:00
Use await keyword as soon as possible to yield to the event event loop
This commit is contained in:
parent
56dc449096
commit
4848e6f600
@ -137,8 +137,14 @@ proc runCodex(ctx: ptr CodexContext) {.async: (raises: []).} =
|
||||
error "codex thread could not receive a request"
|
||||
continue
|
||||
|
||||
# Dispatch the request to be processed asynchronously
|
||||
asyncSpawn CodexThreadRequest.process(request, addr codex)
|
||||
# yield immediately to the event loop
|
||||
# with asyncSpawn only, the code will be executed
|
||||
# synchronously until the first await
|
||||
asyncSpawn (
|
||||
proc() {.async.} =
|
||||
await sleepAsync(0)
|
||||
await CodexThreadRequest.process(request, addr codex)
|
||||
)()
|
||||
|
||||
# Notify the main thread that we picked up the request
|
||||
let fireRes = ctx.reqReceivedSignal.fireSync()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user