Skip to content

Commit 8d193e4

Browse files
author
David Barsky
committed
introduce tokio-threadpool
1 parent 34ee19b commit 8d193e4

File tree

7 files changed

+13
-7
lines changed

7 files changed

+13
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lambda-http/src/request.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use http::{
99
HeaderMap, Method, Request as HttpRequest,
1010
};
1111
use serde::{
12-
de::{Error as DeError, MapAccess, Visitor}, Deserialize, Deserializer
12+
de::{Error as DeError, MapAccess, Visitor},
13+
Deserialize, Deserializer,
1314
};
1415
use serde_json::Value;
1516

lambda-http/src/response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use http::{
99
};
1010
use serde::{
1111
ser::{Error as SerError, SerializeMap},
12-
Serializer, Serialize, Deserialize
12+
Deserialize, Serialize, Serializer,
1313
};
1414

1515
use crate::body::Body;

lambda-http/src/strmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66

77
use serde::{
88
de::{MapAccess, Visitor},
9-
Deserialize, Deserializer
9+
Deserialize, Deserializer,
1010
};
1111

1212
/// A read-only view into a map of string data which may contain multiple values

lambda-runtime-client-simple/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ futures = "^0.1"
1111
hyper = "^0.12"
1212
http = "^0.1"
1313
tokio = "^0.1"
14+
tokio-threadpool = "^0.1"
1415
envy = "0.3"
1516
tower-service = { version = "0.2", git = "https://github.com/tower-rs/tower.git" }
1617
tower-retry = { version = "0.1", git = "https://github.com/tower-rs/tower.git" }

lambda-runtime-client-simple/examples/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bytes::Bytes;
2-
use simple_lambda_runtime::{Error, lambda};
2+
use simple_lambda_runtime::{lambda, Error};
33

44
fn main() {
55
let handler = |event: Bytes| -> Result<Bytes, Error> { unimplemented!() };

lambda-runtime-client-simple/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ extern crate serde_derive;
44
use crate::{hyper_tower::*, settings::Config};
55
use bytes::{buf::FromBuf, Bytes, IntoBuf};
66
use futures::{
7-
future::{result, FutureResult},
7+
future::{poll_fn, result, FutureResult},
88
Async, Future, Poll,
99
};
1010
use http::{Method, Request, Response, Uri};
11+
use tokio_threadpool::blocking;
1112
use tower_service::Service;
1213
use tower_util::ServiceFn;
1314

@@ -74,9 +75,11 @@ where
7475
.next_event()
7576
.and_then(move |event| {
7677
let body = event.into_body();
77-
f.run(body)
78+
poll_fn(move || {
79+
blocking(|| f.run(body.clone()))
80+
}).map_err(|_| panic!("the threadpool shut down"))
7881
})
79-
.then(move |res| match res {
82+
.and_then(move |res| match res {
8083
Ok(bytes) => runtime.ok_response(bytes),
8184
Err(e) => runtime.err_response(Bytes::from(catch(e))),
8285
})

0 commit comments

Comments
 (0)