method Client.idleConnections
Keep-alive connections waiting in the pool.
Example:
use std.http { Server, ServerConfig, ServerHandle, Router, Request, Reply, Client, Header, HttpConfig, Response, Middleware, Next, withMiddleware, requireHeader, logRequests, timing, WebSocket, WsConfig, SseWriter, BodyWriter, chunks }
fn body(req: Request) -> str {
match req.text() {
str t => t
DecodeError _ => ""
}
}
fn run() -> () | NetError | DecodeError | Panicked net, io, time {
let srv = Server.bind(ServerConfig{ port: 0, followNode: false })?
defer srv.close()
let stop = srv.handle()
let base = "http://127.0.0.1:{srv.port()}"
let router = Router.new().get("/a", (req: Request) => Reply.text("a"))
scope {
spawn stop.serve(router)
let _ = Client.get("{base}/a")?
print("idle: {Client.idleConnections()}")
Client.closeIdle()
print("idle: {Client.idleConnections()}")
stop.shutdown()
()
}?
}
fn main() io, net, time {
match run() {
NetError _ => print("net error")
DecodeError _ => print("decode error")
Panicked _ => print("panicked")
_ => {}
}
}Вывод
idle: 1 idle: 0
pub(api) static fn idleConnections() -> i64Потокобезопасность. a process-wide counter, safe to read from any task.
С версии. 1.0.0-beta
Возвращает
i64
Эффекты
не объявлены (чистая, пока тело не говорит иное)
Определено в: std/http/http.oxl:1002