Skip to content

Commit

Permalink
Merge pull request #149 from roc-lang/fix_issue_146
Browse files Browse the repository at this point in the history
Fix issue 146
  • Loading branch information
Anton-4 authored Jan 26, 2024
2 parents 865c615 + d5289e7 commit 0896641
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
4 changes: 0 additions & 4 deletions ci/expect_scripts/http-get.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "</html>\r\n" {
expect eof {
check_exit_and_segfault
Expand Down
37 changes: 14 additions & 23 deletions examples/http-get.roc
Original file line number Diff line number Diff line change
@@ -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: TimeoutMilliseconds 5000,
}

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
2 changes: 1 addition & 1 deletion platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,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,
},
Expand Down

0 comments on commit 0896641

Please sign in to comment.