-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpool.mli
More file actions
48 lines (40 loc) · 1.66 KB
/
Copy pathpool.mli
File metadata and controls
48 lines (40 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(*
Pools of reusable connections, growing to a configurable capacity
- taking a connection from the pool consists in taking a connection from
a queue of connections available for reuse; if the queue is empty,
a new connection is created
- when done with a connection, it is added back to the queue; if the
queue is full, the connection is closed and not added to the queue.
- no more than the configurable max_live_conn connections exist
simultaneously
*)
val create_throttler : int -> ((unit -> 'a Lwt.t) -> 'a Lwt.t)
(* [create_throttler n] creates a function [throttle]
which will create an lwt thread as soon as fewer than [n]
threads are running. *)
module type Connection = sig
type conn
val create_connection : unit -> conn Lwt.t
val close_connection : conn -> unit Lwt.t
val is_reusable : conn -> bool Lwt.t
end
module type S = sig
type conn
type connection_pool
val create_pool :
capacity:int ->
max_live_conn:int -> connection_pool
(* capacity: maximum number of unused connections to keep around
for later reuse
max_live_conn:
maximum number of connections existing simultaneously.
max_live_conn must be greater than or equal to capacity.
*)
val with_connection : connection_pool -> (conn -> 'a Lwt.t) -> 'a Lwt.t
(* Run an arbitrary function with connection reused from the pool
or freshly created. This obeys max_live_conn by waiting
until the number of simultaneous connections drops below max_live_conn.
*)
end
module Make : functor (C : Connection) -> S with type conn = C.conn
val tests : (string * (unit -> bool)) list