You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to call asynchronous code from a service config function?
It almost seems like a 1-to-1 use case compared to invoking the app, except the main function is async.
Run external configuration as part of the scope building process.
This function is useful for moving parts of configuration to a different module or library. For example, some of the resource's configuration could be moved to different module.
use actix_web::{web, middleware,App,HttpResponse};// this function could be located in different modulefnconfig(cfg:&mut web::ServiceConfig){
cfg.service(web::resource("/test").route(web::get().to(|| HttpResponse::Ok())).route(web::head().to(|| HttpResponse::MethodNotAllowed())));}let app = App::new().wrap(middleware::Logger::default()).service(
web::scope("/api").configure(config)).route("/index.html", web::get().to(|| HttpResponse::Ok()));
I would love to do something like this:
use actix_web::{web, middleware,App,HttpResponse};// this function could be located in different moduleasyncfnconfig(cfg:&mut web::ServiceConfig){let some_async_value = some_async_function().await;
cfg.service(web::resource("/test").route(web::get().to(|| HttpResponse::Ok())).route(web::head().to(|| HttpResponse::MethodNotAllowed())));}let app = App::new().wrap(middleware::Logger::default()).service(
web::scope("/api").configure(config)).route("/index.html", web::get().to(|| HttpResponse::Ok()));
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Is there a way to call asynchronous code from a service config function?
It almost seems like a 1-to-1 use case compared to invoking the app, except the main function is async.
I would love to do something like this:
Beta Was this translation helpful? Give feedback.
All reactions