Skip to content

Commit ed7886b

Browse files
committed
Make sure the example still builds.
1 parent 0055e24 commit ed7886b

File tree

2 files changed

+104
-103
lines changed

2 files changed

+104
-103
lines changed

example-async/package-lock.json

+5-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example-async/src/AA.mjs

+99-100
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ function addTest(t) {
1515

1616
function addTest1(t, x) {
1717
tests.push(function () {
18-
return t(x);
19-
});
18+
return t(x);
19+
});
2020
}
2121

2222
async function foo(x, y) {
23-
return (x + y) | 0;
23+
return x + y | 0;
2424
}
2525

2626
async function bar(ff) {
2727
var a = await ff(3, 4);
2828
var b = await foo(5, 6);
29-
return (a + b) | 0;
29+
return a + b | 0;
3030
}
3131

3232
async function baz() {
@@ -40,14 +40,14 @@ async function testBaz() {
4040

4141
tests.push(testBaz);
4242

43-
var E = /* @__PURE__ */ Caml_exceptions.create("AA.E");
43+
var E = /* @__PURE__ */Caml_exceptions.create("AA.E");
4444

4545
async function e1() {
4646
throw {
47-
RE_EXN_ID: E,
48-
_1: 1000,
49-
Error: new Error(),
50-
};
47+
RE_EXN_ID: E,
48+
_1: 1000,
49+
Error: new Error()
50+
};
5151
}
5252

5353
async function e2() {
@@ -62,22 +62,21 @@ async function e4() {
6262
return await e2();
6363
}
6464

65-
var e5 = function () {
66-
return Promise.reject(new Error("fail"));
67-
};
65+
var e5 = (function() { return Promise.reject(new Error('fail')) });
6866

6967
async function testTryCatch(fn) {
7068
try {
7169
return await fn();
72-
} catch (raw_n) {
70+
}
71+
catch (raw_n){
7372
var n = Caml_js_exceptions.internalToOCamlException(raw_n);
7473
if (n.RE_EXN_ID === E) {
7574
console.log("testTryCatch: E", n._1);
76-
return;
75+
return ;
7776
}
7877
if (n.RE_EXN_ID === "JsError") {
7978
console.log("testTryCatch: JsError");
80-
return;
79+
return ;
8180
}
8281
throw n;
8382
}
@@ -94,11 +93,11 @@ addTest1(testTryCatch, e4);
9493
addTest1(testTryCatch, e5);
9594

9695
async function singlePromise(x) {
97-
return (x + 1) | 0;
96+
return x + 1 | 0;
9897
}
9998

10099
async function nestedPromise(x) {
101-
var x$1 = singlePromise((x + 1) | 0);
100+
var x$1 = singlePromise(x + 1 | 0);
102101
[Promise.resolve(x$1)];
103102
return 32;
104103
}
@@ -113,20 +112,21 @@ function status(response) {
113112

114113
var Fetch = {
115114
$$fetch: $$fetch$1,
116-
status: status,
115+
status: status
117116
};
118117

119-
var explainError = e => e.toString();
118+
var explainError = ((e)=>e.toString());
120119

121120
async function testFetch(url) {
122121
var response;
123122
try {
124123
response = await fetch(url);
125-
} catch (raw_e) {
124+
}
125+
catch (raw_e){
126126
var e = Caml_js_exceptions.internalToOCamlException(raw_e);
127127
if (e.RE_EXN_ID === "JsError") {
128128
console.log("Fetch returned an error:", explainError(e._1));
129-
return;
129+
return ;
130130
}
131131
throw e;
132132
}
@@ -140,7 +140,7 @@ addTest1(testFetch, "https://www.google.comsdkjdkghdsg");
140140

141141
async function withCallback() {
142142
return async function (x) {
143-
return ((await Promise.resolve(x)) + 1) | 0;
143+
return await Promise.resolve(x) + 1 | 0;
144144
};
145145
}
146146

@@ -154,58 +154,55 @@ async function map(l, f) {
154154
var loop = async function (l, acc) {
155155
if (l) {
156156
return await loop(l.tl, {
157-
hd: await l.hd,
158-
tl: acc,
159-
});
157+
hd: await l.hd,
158+
tl: acc
159+
});
160160
} else {
161161
return acc;
162162
}
163163
};
164-
return await loop(
165-
Belt_List.mapReverse(l, function (x) {
166-
return f(x);
167-
}),
168-
/* [] */ 0
169-
);
164+
return await loop(Belt_List.mapReverse(l, (function (x) {
165+
return f(x);
166+
})), /* [] */0);
170167
}
171168

172169
var AsyncList = {
173-
map: map,
170+
map: map
174171
};
175172

176173
var counter = {
177-
contents: 0,
174+
contents: 0
178175
};
179176

180177
async function ff(url) {
181178
var response = await fetch(url);
182-
counter.contents = (counter.contents + 1) | 0;
183-
return [counter.contents, response.status];
179+
counter.contents = counter.contents + 1 | 0;
180+
return [
181+
counter.contents,
182+
response.status
183+
];
184184
}
185185

186186
async function testFetchMany() {
187-
var fetchedItems = await map(
188-
{
189-
hd: "https://www.google.com",
190-
tl: {
187+
var fetchedItems = await map({
191188
hd: "https://www.google.com",
192189
tl: {
193190
hd: "https://www.google.com",
194191
tl: {
195192
hd: "https://www.google.com",
196193
tl: {
197194
hd: "https://www.google.com",
198-
tl: /* [] */ 0,
199-
},
200-
},
201-
},
202-
},
203-
},
204-
ff
205-
);
206-
return Belt_List.forEach(fetchedItems, function (param) {
207-
console.log("Fetched", param[0], param[1]);
208-
});
195+
tl: {
196+
hd: "https://www.google.com",
197+
tl: /* [] */0
198+
}
199+
}
200+
}
201+
}
202+
}, ff);
203+
return Belt_List.forEach(fetchedItems, (function (param) {
204+
console.log("Fetched", param[0], param[1]);
205+
}));
209206
}
210207

211208
tests.push(testFetchMany);
@@ -214,24 +211,25 @@ async function $$fetch$2(url) {
214211
var response;
215212
try {
216213
response = await fetch(url);
217-
} catch (raw_e) {
214+
}
215+
catch (raw_e){
218216
var e = Caml_js_exceptions.internalToOCamlException(raw_e);
219217
if (e.RE_EXN_ID === "JsError") {
220218
return {
221-
TAG: /* Error */ 1,
222-
_0: e._1,
223-
};
219+
TAG: /* Error */1,
220+
_0: e._1
221+
};
224222
}
225223
throw e;
226224
}
227225
return {
228-
TAG: /* Ok */ 0,
229-
_0: response,
230-
};
226+
TAG: /* Ok */0,
227+
_0: response
228+
};
231229
}
232230

233231
var FetchResult = {
234-
$$fetch: $$fetch$2,
232+
$$fetch: $$fetch$2
235233
};
236234

237235
function nextFetch(_response) {
@@ -240,18 +238,18 @@ function nextFetch(_response) {
240238

241239
async function testFetchWithResult() {
242240
var response1 = await $$fetch$2("https://www.google.com");
243-
if (response1.TAG !== /* Ok */ 0) {
244-
return;
241+
if (response1.TAG !== /* Ok */0) {
242+
return ;
245243
}
246244
var response1$1 = response1._0;
247245
console.log("FetchResult response1", response1$1.status);
248246
var url = nextFetch(response1$1);
249247
if (url === undefined) {
250-
return;
248+
return ;
251249
}
252250
var response2 = await $$fetch$2(url);
253-
if (response2.TAG !== /* Ok */ 0) {
254-
return;
251+
if (response2.TAG !== /* Ok */0) {
252+
return ;
255253
}
256254
console.log("FetchResult response2", response2._0.status);
257255
}
@@ -261,8 +259,9 @@ tests.push(testFetchWithResult);
261259
async function runAllTests(n) {
262260
if (n >= 0 && n < tests.length) {
263261
await Caml_array.get(tests, n)();
264-
return await runAllTests((n + 1) | 0);
262+
return await runAllTests(n + 1 | 0);
265263
}
264+
266265
}
267266

268267
runAllTests(0);
@@ -273,51 +272,51 @@ async function bb(x) {
273272

274273
async function cc(x, yOpt, z) {
275274
var y = yOpt !== undefined ? Caml_option.valFromOption(yOpt) : x;
276-
return ((((await x) + (await y)) | 0) + (await z)) | 0;
275+
return (await x + await y | 0) + await z | 0;
277276
}
278277

279278
async function dd(x, y) {
280-
return ((await x) + (await y)) | 0;
279+
return await x + await y | 0;
281280
}
282281

283282
async function ee(x, y) {
284-
return ((await x) + (await y)) | 0;
283+
return await x + await y | 0;
285284
}
286285

287286
var fetchAndCount = ff;
288287

289288
export {
290-
tests,
291-
addTest,
292-
addTest1,
293-
foo,
294-
bar,
295-
baz,
296-
testBaz,
297-
E,
298-
e1,
299-
e2,
300-
e3,
301-
e4,
302-
e5,
303-
testTryCatch,
304-
singlePromise,
305-
nestedPromise,
306-
Fetch,
307-
explainError,
308-
testFetch,
309-
withCallback,
310-
testWithCallback,
311-
AsyncList,
312-
fetchAndCount,
313-
testFetchMany,
314-
FetchResult,
315-
nextFetch,
316-
testFetchWithResult,
317-
runAllTests,
318-
bb,
319-
cc,
320-
dd,
321-
ee,
322-
};
289+
tests ,
290+
addTest ,
291+
addTest1 ,
292+
foo ,
293+
bar ,
294+
baz ,
295+
testBaz ,
296+
E ,
297+
e1 ,
298+
e2 ,
299+
e3 ,
300+
e4 ,
301+
e5 ,
302+
testTryCatch ,
303+
singlePromise ,
304+
nestedPromise ,
305+
Fetch ,
306+
explainError ,
307+
testFetch ,
308+
withCallback ,
309+
testWithCallback ,
310+
AsyncList ,
311+
fetchAndCount ,
312+
testFetchMany ,
313+
FetchResult ,
314+
nextFetch ,
315+
testFetchWithResult ,
316+
runAllTests ,
317+
bb ,
318+
cc ,
319+
dd ,
320+
ee ,
321+
}
323322
/* Not a pure module */

0 commit comments

Comments
 (0)