-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
promise.rei
235 lines (167 loc) · 4.22 KB
/
promise.rei
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/* This file is part of reason-promise, released under the MIT license. See
LICENSE.md for details, or visit
https://github.com/aantron/promise/blob/master/LICENSE.md. */
type rejectable(+'a, +'e); /* Internal; use Promise.Js.t. */
type never;
type promise(+'a) = rejectable('a, never); /* Internal; use Promise.t. */
type t(+'a) = promise('a);
/* Making promises. */
let pending:
unit =>
(promise('a), 'a => unit);
let resolved:
'a =>
promise('a);
let exec:
(('a => unit) => unit) =>
promise('a);
/* Using promises. */
let get:
(promise('a), 'a => unit) =>
unit;
let tap:
(promise('a), 'a => unit) =>
promise('a);
let map:
(promise('a), 'a => 'b) =>
promise('b);
let flatMap:
(promise('a), 'a => promise('b)) =>
promise('b);
/* Compatibility with BuckleScript < 6. */
type result('a, 'e) = Belt.Result.t('a, 'e);
/* Results. */
let getOk:
(promise(result('a, 'e)), 'a => unit) =>
unit;
let tapOk:
(promise(result('a, 'e)), 'a => unit) =>
promise(result('a, 'e));
let mapOk:
(promise(result('a, 'e)), 'a => 'b) =>
promise(result('b, 'e));
let flatMapOk:
(promise(result('a, 'e)), 'a => promise(result('b, 'e))) =>
promise(result('b, 'e));
let getError:
(promise(result('a, 'e)), 'e => unit) =>
unit;
let tapError:
(promise(result('a, 'e)), 'e => unit) =>
promise(result('a, 'e));
let mapError:
(promise(result('a, 'e)), 'e => 'e2) =>
promise(result('a, 'e2));
let flatMapError:
(promise(result('a, 'e)), 'e => promise(result('a, 'e2))) =>
promise(result('a, 'e2));
module Operators: {
[@ocaml.deprecated "Use bs-let"]
let (>|=):
(promise(result('a, 'e)), 'a => 'b) =>
promise(result('b, 'e));
[@ocaml.deprecated "Use bs-let"]
let (>>=):
(promise(result('a, 'e)), 'a => promise(result('b, 'e))) =>
promise(result('b, 'e));
};
/* Options. */
let getSome:
(promise(option('a)), 'a => unit) =>
unit;
let tapSome:
(promise(option('a)), 'a => unit) =>
promise(option('a));
let mapSome:
(promise(option('a)), 'a => 'b) =>
promise(option('b));
let flatMapSome:
(promise(option('a)), 'a => promise(option('b))) =>
promise(option('b));
/* Combining promises. */
let race:
list(promise('a)) =>
promise('a);
let all:
list(promise('a)) =>
promise(list('a));
let allArray:
array(promise('a)) =>
promise(array('a));
let all2:
(promise('a), promise('b)) =>
promise(('a, 'b));
let all3:
(promise('a), promise('b), promise('c)) =>
promise(('a, 'b, 'c));
let all4:
(promise('a), promise('b), promise('c), promise('d)) =>
promise(('a, 'b, 'c, 'd));
let all5:
(promise('a), promise('b), promise('c), promise('d), promise('e)) =>
promise(('a, 'b, 'c, 'd, 'e));
let all6:
(promise('a),
promise('b),
promise('c),
promise('d),
promise('e),
promise('f)) =>
promise(('a, 'b, 'c, 'd, 'e, 'f));
/* For writing bindings. */
module Js: {
type t(+'a, +'e) = rejectable('a, 'e);
/* Making. */
let pending:
unit =>
(rejectable('a, 'e), 'a => unit, 'e => unit);
let resolved:
'a =>
rejectable('a, 'e);
let rejected:
'e =>
rejectable('a, 'e);
/* Handling fulfillment. */
let get:
(rejectable('a, 'e), 'a => unit) =>
unit;
let tap:
(rejectable('a, 'e), 'a => unit) =>
rejectable('a, 'e);
let map:
(rejectable('a, 'e), 'a => 'b) =>
rejectable('b, 'e);
let flatMap:
(rejectable('a, 'e), 'a => rejectable('b, 'e)) =>
rejectable('b, 'e);
/* Handling rejection. */
let catch:
(rejectable('a, 'e), 'e => rejectable('a, 'e2)) =>
rejectable('a, 'e2);
/* Combining. */
let all:
list(rejectable('a, 'e)) =>
rejectable(list('a), 'e);
let race:
list(rejectable('a, 'e)) =>
rejectable('a, 'e);
/* Conversions. */
let relax:
promise('a) =>
rejectable('a, 'e);
let toResult:
rejectable('a, 'e) =>
promise(result('a, 'e));
let fromResult:
promise(result('a, 'e)) =>
rejectable('a, 'e);
let fromBsPromise:
Js.Promise.t('a) =>
rejectable('a, Js.Promise.error);
let toBsPromise:
rejectable('a, _) =>
Js.Promise.t('a);
};
module PipeFirst: {
};
let onUnhandledException: ref(exn => unit);