2023-11-01 03:32:09 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2023 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
2023-09-06 09:18:26 +00:00
|
|
|
import
|
|
|
|
json_rpc/rpcclient,
|
|
|
|
./engine_env
|
|
|
|
|
|
|
|
type
|
|
|
|
ClientPool* = ref object
|
|
|
|
clients: seq[EngineEnv]
|
|
|
|
|
|
|
|
proc add*(pool: ClientPool, client: EngineEnv) =
|
|
|
|
pool.clients.add client
|
|
|
|
|
|
|
|
func first*(pool: ClientPool): EngineEnv =
|
|
|
|
pool.clients[0]
|
|
|
|
|
|
|
|
func len*(pool: ClientPool): int =
|
|
|
|
pool.clients.len
|
|
|
|
|
|
|
|
func `[]`*(pool: ClientPool, idx: int): EngineEnv =
|
|
|
|
pool.clients[idx]
|
|
|
|
|
|
|
|
iterator items*(pool: ClientPool): EngineEnv =
|
|
|
|
for x in pool.clients:
|
|
|
|
yield x
|
2023-10-31 03:18:37 +00:00
|
|
|
|
|
|
|
proc remove*(pool: ClientPool, client: EngineEnv) =
|
|
|
|
var index = -1
|
|
|
|
for i, x in pool.clients:
|
|
|
|
if x == client:
|
|
|
|
index = i
|
|
|
|
break
|
|
|
|
if index != -1:
|
|
|
|
pool.clients.delete(index)
|