how to access global shared variables in async handler
lost22git opened this issue · 0 comments
lost22git commented
code
handle
var lock = newAsyncLock()
var fighters = @[
Fighter(id: $genOid(), name: "隆", skill: @["波动拳"], createdAt: now().utc),
Fighter(id: $genOid(), name: "肯", skill: @["升龙拳"], createdAt: now().utc)
]
proc listFighters(ctx: Context) {.async.} =
await lock.acquire()
try:
resp jsonResponse(ok(fighters).toJson)
finally:
lock.release()
routing
var fighterApi = app.newGroup("/fighter", @[])
fighterApi.get("", listFighters)
error msg:
Expression: get(fighterApi, "", listFighters)
[1] fighterApi: Group
[2] "": string
[3] listFighters: proc (ctx: Context): Future[system.void]
Expected one of (first mismatch at [position]):
[1] func get(env: Env; key: string): string
[1] proc get(app: Prologue; route: string; handler: HandlerAsync; name = "";
middlewares: openArray[HandlerAsync] = @[])
[1] proc get[T](aq: AsyncQueue[T]): Future[T]
[1] proc get[T](self: Option[T]): lent T
[1] proc get[T](self: Option[T]; otherwise: T): T
[1] proc get[T](self: var Option[T]): var T
[3] proc get(group: Group; route: string; handler: HandlerAsync; name = "";
middlewares: openArray[HandlerAsync] = @[])
nimble.nim(229) buildFromDir