blob: f740c1ad1089a83549350743b2626bcac5fb03a6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
module Error = struct
open Concepts.Condition
let not_a_session () =
condition "not-a-session" "A handle was expected to carry the session protocol and did not"
empty
end
type state = {branch: string; snapshot: Concepts.Hash.hash}
class type implementation = object
method state : state
method pin : state -> unit
end
type Handle.protocol += Session of implementation
type t = implementation
let make impl = Session (impl :> implementation)
let from handle = Handle.into handle (function Session impl -> Some impl | _ -> None)
let require handle = from handle |> Option.to_result ~none:(Error.not_a_session ())
let state i = Handle.invoke i (fun o -> o#state)
let pin i state = Handle.invoke i (fun o -> o#pin state)
|