fix improper yield usage (#175)

`yield` does not work with chronos futures
This commit is contained in:
Jacek Sieka 2023-12-13 03:21:50 +01:00 committed by GitHub
parent a8731e91bc
commit 33360528d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 19 deletions

View File

@ -29,12 +29,10 @@ proc rpcCallNode*(path: string, params: JsonNode, id: ClientId): JsonNode =
%{"jsonrpc": %"2.0", "method": %path, "params": params, "id": %id}
method call*(client: RpcClient, name: string,
params: JsonNode): Future[Response] {.
base, async, gcsafe, raises: [Defect].} =
params: JsonNode): Future[Response] {.base, async.} =
discard
method close*(client: RpcClient): Future[void] {.
base, async, gcsafe, raises: [Defect].} =
method close*(client: RpcClient): Future[void] {.base, async.} =
discard
template `or`(a: JsonNode, b: typed): JsonNode =

View File

@ -39,21 +39,25 @@ proc processClientRpc(rpcServer: RpcHttpServer): HttpProcessCallback =
if not res.isNil:
return res
let body = await request.getBody()
let headers = HttpTable.init([("Content-Type",
let
body = await request.getBody()
headers = HttpTable.init([("Content-Type",
"application/json; charset=utf-8")])
let future = rpcServer.route(string.fromBytes(body))
yield future
if future.failed:
data =
try:
await rpcServer.route(string.fromBytes(body))
except CancelledError as exc:
raise exc
except CatchableError as exc:
debug "Internal error while processing JSON-RPC call"
return await request.respond(Http503,
"Internal error while processing JSON-RPC call",
return await request.respond(
Http503,
"Internal error while processing JSON-RPC call: " & exc.msg,
headers)
else:
var data = future.read()
let res = await request.respond(Http200, data, headers)
res = await request.respond(Http200, data, headers)
trace "JSON-RPC result has been sent"
return res
else: