package resource_cache

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file resource_intf.ml

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
open! Core
open! Async_kernel
open! Import

module type Simple = sig
  module Key : sig
    type t [@@deriving sexp_of]

    include Comparable.S_plain with type t := t
    include Hashable.S_plain with type t := t
  end

  module Common_args : T

  type t

  val open_ : Key.t -> Common_args.t -> t Or_error.t Deferred.t
  val close : t -> unit Deferred.t
end

module type S = sig
  module Key : sig
    type t [@@deriving sexp_of]

    include Comparable.S_plain with type t := t
    include Hashable.S_plain with type t := t
  end

  module Common_args : T

  type t

  val open_ : Key.t -> Common_args.t -> t Deferred.Or_error.t
  val close : t -> unit Deferred.t

  (** When [close_finished] is determined, the resource will not be reused by a new job.
      If no job is currently using this resource, the resource will be dropped from the
      cache immediately. If there is a currently running job with this resource, the
      resource will be dropped from the cache once that job finishes. *)
  val close_finished : t -> unit Deferred.t

  (** [has_close_started t] should return [true] iff [close t] has been called, even if
      [close_finished] has not been determined. *)
  val has_close_started : t -> bool
end

module type S_wrapped = sig
  include S

  type resource

  val underlying : t -> resource
end

module type Resource = sig
  module type S = S
  module type S_wrapped = S_wrapped
  module type Simple = Simple

  (** Wrap a resource that does not natively support a [has_close_started] operation
      in a simple record to add such tracking. *)
  module Make_simple (R : Simple) :
    S_wrapped
    with module Key = R.Key
     and module Common_args = R.Common_args
     and type resource = R.t
end
OCaml

Innovation. Community. Security.