Skip to content

Commit

Permalink
React-Actix_Ex: main.rs: Move Metacall Initialization to main function
Browse files Browse the repository at this point in the history
Previously Metacall was initialized it every POST request and this is not a good practice as the intialization was redundant so moving it to main function will initialize metacall only once and its the expected behaviour
  • Loading branch information
thequantumquirk committed Dec 14, 2022
1 parent ad5a9f1 commit 5ca287c
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@ use actix_web::{get, App, HttpResponse, HttpServer, Responder};

#[get("/")]
async fn hello() -> impl Responder {
match metacall::initialize() {
Err(e) => {
println!("{}", e);
panic!();
}
_ => println!("MetaCall initialized"),
}

let scripts = ["helloworld.ts".to_string()];

if let Err(e) = metacall::load_from_file("ts", &scripts) {
println!("{}", e);
panic!();
}

match metacall::metacall(
"helloWorld", &[metacall::Any::Str("World".to_string())]
) {
Expand All @@ -37,6 +22,20 @@ async fn hello() -> impl Responder {

#[actix_web::main]
async fn main() -> std::io::Result<()> {
match metacall::initialize() {
Err(e) => {
println!("{}", e);
panic!();
}
_ => println!("MetaCall initialized"),
}

let scripts = ["helloworld.ts".to_string()];

if let Err(e) = metacall::load_from_file("ts", &scripts) {
println!("{}", e);
panic!();
}
HttpServer::new(|| {
App::new()
.service(hello)
Expand Down

0 comments on commit 5ca287c

Please sign in to comment.