Skip to content
Prev Previous commit
Review comments
  • Loading branch information
illicitonion committed Jan 13, 2019
commit 5d1de6df98fa064bba6cab995a30df6ca9dd0fe2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub trait Handler<E, O>: Send {

`Handler` provides a default implementation that enables you to provide a Rust closure or function pointer to the `lambda!()` macro.

If your handler is synchronous, you can just return a `Result` from it; if your handler is asynchronous, you can return a `Future` from it.
Your `Handler` needs to return something which implements `IntoFuture`; `Result` implements `IntoIterator`, so most synchronous `Handler`s will return a `Result`.

Optionally, you can pass your own instance of Tokio runtime to the `lambda!()` macro. See our [`with_custom_runtime.rs` example](https://github.com/awslabs/aws-lambda-rust-runtime/tree/master/lambda-runtime/examples/with_custom_runtime.rs)

Expand Down
4 changes: 2 additions & 2 deletions lambda-runtime-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ pub struct RuntimeClient {
impl RuntimeClient {
/// Creates a new instance of the Runtime APIclient SDK. The http client has timeouts disabled and
/// will always send a `Connection: keep-alive` header.
pub fn new(endpoint: String, task_executor: TaskExecutor) -> Result<Self, ApiError> {
pub fn new(endpoint: String, task_executor: TaskExecutor) -> Self {
debug!("Starting new HttpRuntimeClient for {}", endpoint);
// start a tokio core main event loop for hyper

let http_client = Client::builder().executor(task_executor).build_http();

Ok(RuntimeClient { http_client, endpoint })
RuntimeClient { http_client, endpoint }
}
}

Expand Down
3 changes: 1 addition & 2 deletions lambda-runtime-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
//! fn main() {
//! let tokio_runtime = TokioRuntime::new().expect("Could not make tokio runtime");
//! let runtime_endpoint = String::from("http://localhost:8080");
//! let client = RuntimeClient::new(runtime_endpoint, tokio_runtime.executor())
//! .expect("Could not initialize client");
//! let client = RuntimeClient::new(runtime_endpoint, tokio_runtime.executor());
//!
//! let (event_data, event_context) = client.next_event().wait()
//! .expect("Could not retrieve next event");
Expand Down
10 changes: 2 additions & 8 deletions lambda-runtime/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,7 @@ where
}
}

match RuntimeClient::new(endpoint, task_executor) {
Ok(client) => start_with_runtime_client(f, function_config, client),
Err(e) => {
panic!("Could not create runtime client SDK: {}", e);
}
}
start_with_runtime_client(f, function_config, RuntimeClient::new(endpoint, task_executor))
}

/// Starts the rust runtime with the given Runtime API client.
Expand Down Expand Up @@ -398,8 +393,7 @@ pub(crate) mod tests {
.get_runtime_api_endpoint()
.expect("Could not get runtime endpoint"),
runtime.executor(),
)
.expect("Could not initialize client");
);
let handler = |_e: String, _c: context::Context| -> Result<String, HandlerError> { Ok("hello".to_string()) };
let retries: i8 = 3;
let runtime = Runtime::new(
Expand Down