package async_kernel

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

Source file deferred_memo.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
open Core
open Deferred_std
module Deferred = Deferred1

let reraise = function
  | Ok x -> x
  | Error exn -> Exn.reraise exn "caught exception in memoized function"
;;

let general (type a) (hashable : (module Hashable.S_plain with type t = a)) f =
  let module Hashable = (val hashable) in
  let f =
    Memo.general ~hashable:Hashable.hashable (fun a ->
      Monitor.try_with
        ~rest:`Log
        ~run:`Now
        (fun () -> f a))
  in
  Staged.stage (fun a -> f a >>| reraise)
;;

let unit f =
  let f =
    Memo.unit (fun () ->
      Monitor.try_with
        ~rest:`Log
        ~run:`Now
        f)
  in
  Staged.stage (fun () -> f () >>| reraise)
;;