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)
|