如何在Lambda处理程序中处理多个异步函数?



我有以下代码:

async fn function_handler(_event: Request) -> Result<Response<Body>, Error> {
let db_eid_cache = create_db_eid_cache();
let table_eid_cache = create_table_eid_cache();
try_join!(db_eid_cache, table_eid_cache);
Ok(Response::builder()
.status(200)
.header("content-type", "application/json")
.body("ok".into())
.map_err(Box::new)?)
}
#[tokio::main]
async fn main() -> Result<(), Error> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.with_target(false)
.without_time()
.init();
run(service_fn(function_handler)).await
}

不能编译:

future cannot be sent between threads safely
the trait `std::marker::Send` is not implemented for `(dyn StdError + 'static)`rustcClick for full compiler diagnostic
join_mod.rs(105, 13): future is not `Send` as this value is used across an await
join_mod.rs(107, 13): the value is later dropped here
lib.rs(185, 16): required by a bound in `lambda_http::run`

我试图为function_handler()返回类型添加Send,但它也不起作用。

添加+ Send + Sync到所有我所加入的函数中的任何一个调用的函数都可以修复这个问题。

Result<String, Box<dyn error::Error + Send + Sync>>

最新更新