Module Persistent_connection.Make
Parameters
Signature
include Persistent_connection_kernel.S
type ttype addressThe address of a service to which one can connect. E.g.
Host_and_port.tis a reasonable choice when making a TCP connection.
module Event : sig ... endval create : server_name:string -> ?on_event:(Event.t -> unit Async_kernel.Deferred.t) -> ?retry_delay:(unit -> Core_kernel.Time_ns.Span.t) -> connect:(address -> conn Core_kernel.Or_error.t Async_kernel.Deferred.t) -> (unit -> address Core_kernel.Or_error.t Async_kernel.Deferred.t) -> tcreate ~server_name ~on_event ~retry_delay get_addressreturns a persistent connection to a server whose host and port are obtained viaget_addressevery time we try to connect. For example,get_addressmight look up a server's host and port in catalog at a particular path to which multiple redundant copies of a service are publishing their location. If one copy dies, we get the address of the another one when looking up the address afterwards.All connection events (see the type above) are passed to the
on_eventcallback, if given. When this callback becomes determined, we move on to the next step in our connection attempt (e.g. we won't actually attempt to connect untilon_event Attempting_to_connectis finished). Note thaton_event Disconnectedwill only be called onceon_event (Connected conn)finishes even if the connection goes down during that callback.`Failed_to_connect errorand`Obtained_address addrevents are only reported if they are distinct from the most recent event of the same type that has taken place since the most recent`Attempting_to_connectevent.Connection is retried after
Time.Span.randomize ~percent:(Percent.of_mult 0.3) (retry_delay ()). The default forretry_delayisconst (sec 10.). Note that what this retry delay actually throttles is the delay between two connection attempts, so when a long-lived connection dies, connection is usually immediately retried, and if that failed, wait for another retry delay and retry.
val connected : t -> conn Async_kernel.Deferred.tconnectedreturns the first available connection from the time it is called. When currently connected, the returned deferred is already determined. Ifclosedhas been called, then the returned deferred is never determined.
close t closes the current connection and stops it from trying to reconnect. After the deferred it returns becomes determined, the last connection has been closed and no others will be attempted.
Note: no close calls are ever generated internally in response to the connection being closed by the other side.
include Persistent_connection_kernel__.Persistent_connection_kernel_intf.Closable with type t := t
val close : t -> unit Async_kernel.Deferred.tclose tcloses the connection. The returned deferred becomes determined once any resources needed to maintain the connection have been released.
val is_closed : t -> boolis_closed treturns true ifclosehas ever been called (even if the returned deferred has not yet been fulfilled).Note that some modules implementing
Closablemay call close internally upon noticing that the connection was closed by the other side. The interface of such a module ought to say that this is the case.
val close_finished : t -> unit Async_kernel.Deferred.tclose_finished tbecomes determined at the same time as the result of the first call toclose.close_finisheddiffers fromclosein that it does not have the side effect of initiating a close.
val create : server_name:string -> ?log:Async.Log.t -> ?on_event:(Event.t -> unit Async.Deferred.t) -> ?retry_delay:(unit -> Core.Time.Span.t) -> connect:(address -> conn Core.Or_error.t Async.Deferred.t) -> (unit -> address Core.Or_error.t Async.Deferred.t) -> t