mirror of
https://github.com/logos-storage/nim-json-rpc.git
synced 2026-02-23 15:13:07 +00:00
[FEATURE] Add additional constructor to the proxy (#108)
This commit is contained in:
parent
147ef3f562
commit
a138c410c5
@ -13,14 +13,22 @@ proc proxyCall(client: RpcHttpClient, name: string): RpcProc =
|
||||
let res = await client.call(name, params)
|
||||
return StringOfJson($res)
|
||||
|
||||
proc new*(T: type RpcHttpProxy, listenAddresses: openArray[string]): T {.raises: [Defect, CatchableError].}=
|
||||
proc new*(T: type RpcHttpProxy, server: RpcHttpServer): T =
|
||||
let client = newRpcHttpClient()
|
||||
let router = RpcRouter.init()
|
||||
T(rpcHttpClient: client, rpcHttpServer: newRpcHttpServer(listenAddresses, router))
|
||||
T(rpcHttpClient: client, rpcHttpServer: server)
|
||||
|
||||
proc new*(T: type RpcHttpProxy, listenAddresses: openArray[TransportAddress]): T {.raises: [Defect, CatchableError].} =
|
||||
RpcHttpProxy.new(newRpcHttpServer(listenAddresses, RpcRouter.init()))
|
||||
|
||||
proc new*(T: type RpcHttpProxy, listenAddresses: openArray[string]): T {.raises: [Defect, CatchableError].} =
|
||||
RpcHttpProxy.new(newRpcHttpServer(listenAddresses, RpcRouter.init()))
|
||||
|
||||
proc newRpcHttpProxy*(listenAddresses: openArray[string]): RpcHttpProxy {.raises: [Defect, CatchableError].} =
|
||||
RpcHttpProxy.new(listenAddresses)
|
||||
|
||||
proc newRpcHttpProxy*(listenAddresses: openArray[TransportAddress]): RpcHttpProxy {.raises: [Defect, CatchableError].} =
|
||||
RpcHttpProxy.new(listenAddresses)
|
||||
|
||||
proc start*(proxy:RpcHttpProxy, proxyServerUrl: string) {.async.} =
|
||||
proxy.rpcHttpServer.start()
|
||||
await proxy.rpcHttpClient.connect(proxyServerUrl)
|
||||
@ -43,4 +51,4 @@ proc stop*(rpcHttpProxy: RpcHttpProxy) {.raises: [Defect, CatchableError].} =
|
||||
rpcHttpProxy.rpcHttpServer.stop()
|
||||
|
||||
proc closeWait*(rpcHttpProxy: RpcHttpProxy) {.async.} =
|
||||
await rpcHttpProxy.rpcHttpServer.closeWait()
|
||||
await rpcHttpProxy.rpcHttpServer.closeWait()
|
||||
|
||||
@ -323,6 +323,11 @@ proc newRpcHttpServer*(addresses: openArray[string], router: RpcRouter): RpcHttp
|
||||
result = newRpcHttpServer(router)
|
||||
result.addStreamServers(addresses)
|
||||
|
||||
proc newRpcHttpServer*(addresses: openArray[TransportAddress], router: RpcRouter): RpcHttpServer =
|
||||
## Create new server and assign it to addresses ``addresses``.
|
||||
result = newRpcHttpServer(router)
|
||||
result.addStreamServers(addresses)
|
||||
|
||||
proc start*(server: RpcHttpServer) =
|
||||
## Start the RPC server.
|
||||
for item in server.servers:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user