Skip to content

Commit

Permalink
feat: Migrate tokio_core uses to tokio
Browse files Browse the repository at this point in the history
Closes gluon-lang#462

BREAKING CHANGE

Upgrade to tokio
  • Loading branch information
Marwes committed Jul 21, 2018
1 parent a6af9aa commit 09a1946
Show file tree
Hide file tree
Showing 18 changed files with 1,387 additions and 1,711 deletions.
309 changes: 81 additions & 228 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ regex = { version = "1", optional = true }
compiletest_rs = { version = "0.3", optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio-core = "0.1"
rand = { version = "0.4", optional = true }

[build-dependencies]
Expand All @@ -56,14 +55,16 @@ walkdir = { version = "2", optional = true }

[dev-dependencies]
bencher = "0.1.2"
tensile = "0.1.0"
tensile = "0.2.0"
collect-mac = "0.1.0"
env_logger = "0.5.0"
pretty_assertions = "0.5"
futures-cpupool = "0.1.8"
tokio = "0.1.7"
tokio-retry = "0.2"

hyper = "0.11.0"
curl = "0.4.1"
hyper = "0.12.0"
http = "0.1.0"

serde = "1.0.0"
serde_derive = "1.0.0"
Expand Down Expand Up @@ -115,8 +116,6 @@ name = "debug"
[[test]]
name = "error"
[[test]]
name = "http"
[[test]]
name = "io"
[[test]]
name = "limits"
Expand Down
34 changes: 24 additions & 10 deletions examples/http/http.glu
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ let {
HttpState } = import! examples.http.types
let http_prim = import! http.prim

let status =
let code : Int -> StatusCode = id
{
ok = code 200,
bad_request = code 400,
not_found = code 404,
internal_server_error = code 500,
}

let method =
let method : String -> Method = id
{
get = method "GET",
post = method "POST",
put = method "PUT",
}

/// Force the value to be a Handler. Necessary to make the the type inference work for
/// higher-kinded types
let make : Handler a -> Handler a = id
Expand Down Expand Up @@ -73,17 +90,11 @@ let test predicate : (Request -> Bool) -> Handler () =

/// Handles `Get` requests
let get : Handler () =
test (\request ->
match request.method with
| Get -> True
| _ -> False)
test (\request -> request.method == method.get)

/// Handles `Post` requests
let post : Handler () =
test (\request ->
match request.method with
| Post -> True
| _ -> False)
test (\request -> request.method == method.post)

/// Processes this handler if `uri` matches the request's uri
let path uri : String -> Handler () =
Expand All @@ -98,7 +109,7 @@ let get_response_body : Handler ResponseBody =
make (\success failure state -> success state.response state)

/// Returns `OK` with an empty body
let empty_response = { status = Ok }
let empty_response = { status = status.ok }

/// Converts an `IO` into a `Handler`
let io_handler action : IO a -> Handler a =
Expand All @@ -125,7 +136,7 @@ let catch_error action catch : Handler a -> (String -> Handler a) -> Handler a =
/// Takes a `Handler` and a `Request` tries to process the request
let handle handler state : Handler Response -> HttpState -> IO Response =
let not_found _ state : _ -> _ -> IO Response =
http_prim.write_response state.response (string.as_bytes "Page not found") *> wrap { status = NotFound }
http_prim.write_response state.response (string.as_bytes "Page not found") *> wrap { status = status.not_found }
handler (\response _ -> wrap response) not_found state

{
Expand All @@ -141,6 +152,9 @@ let handle handler state : Handler Response -> HttpState -> IO Response =
alternative,
monad,

status,
method,

empty_response,
get_request,
handle,
Expand Down
Loading

0 comments on commit 09a1946

Please sign in to comment.