-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathpromise.rei
281 lines (205 loc) · 5.43 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/* 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. */
/* Internal type names; don't use these. Instead, use Promise.t and Promise.Js.t
from outside this library. */
type rejectable(+'a, +'e); /* Internal; use Promise.Js.t. */
type never;
type promise(+'a) = rejectable('a, never); /* Internal; use Promise.t. */
/* The main, public promise type (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));
let allOk:
list(promise(result('a, 'e))) =>
promise(result(list('a), 'e));
let allOkArray:
array(promise(result('a, 'e))) =>
promise(result(array('a), 'e));
let allOk2:
(promise(result('a, 'err)), promise(result('b, 'err))) =>
promise(result(('a, 'b), 'err));
let allOk3:
(promise(result('a, 'err)),
promise(result('b, 'err)),
promise(result('c, 'err))) =>
promise(result(('a, 'b, 'c), 'err));
let allOk4:
(promise(result('a, 'err)),
promise(result('b, 'err)),
promise(result('c, 'err)),
promise(result('d, 'err))) =>
promise(result(('a, 'b, 'c, 'd), 'err));
let allOk5:
(promise(result('a, 'err)),
promise(result('b, 'err)),
promise(result('c, 'err)),
promise(result('d, 'err)),
promise(result('e, 'err))) =>
promise(result(('a, 'b, 'c, 'd, 'e), 'err));
let allOk6:
(promise(result('a, 'err)),
promise(result('b, 'err)),
promise(result('c, 'err)),
promise(result('d, 'err)),
promise(result('e, 'err)),
promise(result('f, 'err))) =>
promise(result(('a, 'b, 'c, 'd, 'e, 'f), 'err));
/* 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);