From a6baebc145d37cbde2122b89aecc34715ba8bc22 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Fri, 29 Dec 2023 16:10:21 +0100 Subject: [PATCH 1/3] simplified http-get example No need to complicate things --- examples/http-get.roc | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/examples/http-get.roc b/examples/http-get.roc index 9cb3cd41..d42a74c2 100644 --- a/examples/http-get.roc +++ b/examples/http-get.roc @@ -1,31 +1,22 @@ app "http-get" packages { pf: "../platform/main.roc" } - imports [pf.Http, pf.Task.{ Task }, pf.Stdin, pf.Stdout] + imports [pf.Http, pf.Task.{ Task }, pf.Stdout] provides [main] to pf main : Task {} I32 main = - _ <- Task.await (Stdout.line "Enter a URL to fetch. It must contain a scheme like \"http://\" or \"https://\".") + request = { + method: Get, + headers: [], + url: "http://www.example.com", + body: Http.emptyBody, + timeout: NoTimeout, + } - input <- Task.await Stdin.line + output <- Http.send request + |> Task.onErr \err -> err + |> Http.errorToString + |> Task.ok + |> Task.await - when input is - End -> - Stdout.line "I received end-of-input (EOF) instead of a URL." - - Input url -> - request = { - method: Get, - headers: [], - url, - body: Http.emptyBody, - timeout: NoTimeout, - } - - output <- Http.send request - |> Task.onErr \err -> err - |> Http.errorToString - |> Task.ok - |> Task.await - - Stdout.line output + Stdout.line output From 4e8fda73dab299a82e46f7ab366c9a1580eeca3b Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Fri, 29 Dec 2023 17:23:46 +0100 Subject: [PATCH 2/3] Fixes #146 --- examples/http-get.roc | 2 +- platform/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/http-get.roc b/examples/http-get.roc index d42a74c2..48fbe337 100644 --- a/examples/http-get.roc +++ b/examples/http-get.roc @@ -10,7 +10,7 @@ main = headers: [], url: "http://www.example.com", body: Http.emptyBody, - timeout: NoTimeout, + timeout: TimeoutMilliseconds 5000, } output <- Http.send request diff --git a/platform/src/lib.rs b/platform/src/lib.rs index 162a6673..99924e60 100644 --- a/platform/src/lib.rs +++ b/platform/src/lib.rs @@ -675,7 +675,7 @@ pub extern "C" fn roc_fx_sendRequest(roc_request: &glue::Request) -> glue::Respo } }; match time_limit { - Some(limit) => match rt.block_on(tokio::time::timeout(limit, http_fn)) { + Some(limit) => match rt.block_on(async { tokio::time::timeout(limit, http_fn).await}) { Ok(res) => res, Err(_) => glue::Response::Timeout, }, From e05b756ca34d23bcab6a8372776ee121999461dc Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Fri, 29 Dec 2023 17:59:01 +0100 Subject: [PATCH 3/3] update test --- ci/expect_scripts/http-get.exp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ci/expect_scripts/http-get.exp b/ci/expect_scripts/http-get.exp index db81641b..ed9d9687 100644 --- a/ci/expect_scripts/http-get.exp +++ b/ci/expect_scripts/http-get.exp @@ -9,10 +9,6 @@ source ./ci/expect_scripts/shared-code.exp spawn $env(EXAMPLES_DIR)http-get -expect -exact "Enter a URL to fetch. It must contain a scheme like \"http://\" or \"https://\".\r\n" - -send -- "http://www.example.com\r" - expect "\r\n" { expect eof { check_exit_and_segfault