package js_of_ocaml-webidl

  1. Overview
  2. Docs

Source file promise.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
open Js_of_ocaml

type 'a t

let _Promise = Js.Unsafe.global##._Promise

let _catch (p : 'a t Js.t) (f : _ -> 'a t Js.t) : 'a t Js.t =
  (Js.Unsafe.coerce p)##_catch (Js.wrap_callback f)
;;

let _then
    (p : 'a t Js.t)
    ?(catch : (_ -> 'b t Js.t) option)
    (f : 'a -> 'b t Js.t)
    : 'b t Js.t
  =
  match catch with
  | None -> (Js.Unsafe.coerce p)##_then (Js.wrap_callback f)
  | Some catch ->
    (Js.Unsafe.coerce p)##_then
      (Js.wrap_callback f)
      (Js.wrap_callback catch)
;;

let resolve_value (v : 'a) : 'a t Js.t =
  Js.Unsafe.meth_call _Promise "resolve" [| Js.Unsafe.inject v |]
;;

let resolve_promise (v : 'a t Js.t) : 'a t Js.t =
  Js.Unsafe.meth_call _Promise "resolve" [| Js.Unsafe.inject v |]
;;

let reject_value (v : 'a) : 'a t Js.t =
  Js.Unsafe.meth_call _Promise "reject" [| Js.Unsafe.inject v |]
;;

let reject_promise (v : 'a t Js.t) : 'a t Js.t =
  Js.Unsafe.meth_call _Promise "rejetct" [| Js.Unsafe.inject v |]
;;

let race (promise_list : 'a t Js.t Js.js_array Js.t) : 'a t Js.t =
  Js.Unsafe.meth_call _Promise "race" [| Js.Unsafe.inject promise_list |]
;;

let all (promise_list : 'a t Js.t Js.js_array Js.t) : 'a t Js.t =
  Js.Unsafe.meth_call _Promise "all" [| Js.Unsafe.inject promise_list |]
;;
OCaml

Innovation. Community. Security.