diff --git a/example-async/bsconfig.json b/example-async/bsconfig.json index 0c8c8cf91..4e7eff1bb 100644 --- a/example-async/bsconfig.json +++ b/example-async/bsconfig.json @@ -1,5 +1,8 @@ { "name": "example-async", + "reanalyze": { + "analysis": ["exception"] + }, "sources": [ { "dir": "src", diff --git a/example-async/src/AA.mjs b/example-async/src/AA.mjs index ac3eb0ab1..eea176489 100644 --- a/example-async/src/AA.mjs +++ b/example-async/src/AA.mjs @@ -102,6 +102,19 @@ async function nestedPromise(x) { return 32; } +function $$fetch$1(url) { + return fetch(url); +} + +function status(response) { + return response.status; +} + +var Fetch = { + $$fetch: $$fetch$1, + status: status +}; + var explainError = ((e)=>e.toString()); async function testFetch(url) { @@ -193,7 +206,7 @@ async function testFetchMany() { tests.push(testFetchMany); -async function $$fetch$1(url) { +async function $$fetch$2(url) { var response; try { response = await fetch(url); @@ -215,7 +228,7 @@ async function $$fetch$1(url) { } var FetchResult = { - $$fetch: $$fetch$1 + $$fetch: $$fetch$2 }; function nextFetch(_response) { @@ -223,7 +236,7 @@ function nextFetch(_response) { } async function testFetchWithResult() { - var response1 = await $$fetch$1("https://www.google.com"); + var response1 = await $$fetch$2("https://www.google.com"); if (response1.TAG !== /* Ok */0) { return ; } @@ -233,7 +246,7 @@ async function testFetchWithResult() { if (url === undefined) { return ; } - var response2 = await $$fetch$1(url); + var response2 = await $$fetch$2(url); if (response2.TAG !== /* Ok */0) { return ; } @@ -288,6 +301,7 @@ export { testTryCatch , singlePromise , nestedPromise , + Fetch , explainError , testFetch , withCallback , diff --git a/example-async/src/AA.res b/example-async/src/AA.res index e7d2418e5..fa52566af 100644 --- a/example-async/src/AA.res +++ b/example-async/src/AA.res @@ -74,14 +74,23 @@ let nestedPromise = // // Test error handling in fetch +module Fetch = { + @raises(JsError) + let fetch = url => Fetch.fetch(url) + + @raises([]) + let status = response => Fetch.Response.status(response) +} + let explainError: unknown => string = %raw(`(e)=>e.toString()`) let testFetch = @async (. url) => { - switch {@await Fetch.fetch(url)} { + open Fetch + switch {@await fetch(url)} { | response => - let status = response->Fetch.Response.status + let status = response->status Js.log2("Fetch returned status:", status) | exception JsError(e) => Js.log2("Fetch returned an error:", e->explainError) } @@ -132,7 +141,7 @@ let fetchAndCount = { (. url) => { let response = @await Fetch.fetch(url) counter := counter.contents + 1 - (counter.contents, response->Fetch.Response.status) + (counter.contents, response->Fetch.status) } ff @@ -177,13 +186,13 @@ let testFetchWithResult = switch @await FetchResult.fetch(. "https://www.google.com") { | Ok(response1) => - Js.log2("FetchResult response1", response1->Fetch.Response.status) + Js.log2("FetchResult response1", response1->Fetch.status) switch nextFetch(. response1) { | None => () | Some(url) => switch @await FetchResult.fetch(. url) { - | Ok(response2) => Js.log2("FetchResult response2", response2->Fetch.Response.status) + | Ok(response2) => Js.log2("FetchResult response2", response2->Fetch.status) | Error(_) => () } }