Don't need mutex, kill it

This commit is contained in:
greg 2017-10-29 04:04:54 -07:00
parent 708c0ab103
commit a42a58b155
2 changed files with 4 additions and 5 deletions

View File

@ -38,7 +38,7 @@ include!(concat!(env!("OUT_DIR"), "/static.rs"));
#[link_args="-ltinfo"]
extern { }
type PLIGenerator = Box<Fn() -> Box<ProgrammingLanguageInterface> + Send>;
type PLIGenerator = Box<Fn() -> Box<ProgrammingLanguageInterface> + Send + Sync>;
fn main() {
let languages: Vec<Box<ProgrammingLanguageInterface>> =

View File

@ -6,7 +6,6 @@ use rocket_contrib::Json;
use language::{ProgrammingLanguageInterface, EvalOptions};
use WEBFILES;
use ::PLIGenerator;
use std::sync::Mutex;
#[get("/")]
fn index() -> Content<String> {
@ -33,12 +32,12 @@ struct Output {
}
#[post("/input", format = "application/json", data = "<input>")]
fn interpreter_input(input: Json<Input>, schala_gen: State<Mutex<PLIGenerator>>) -> Json<Output> {
let mut schala: Box<ProgrammingLanguageInterface> = schala_gen.lock().unwrap()();
fn interpreter_input(input: Json<Input>, schala_gen: State<PLIGenerator>) -> Json<Output> {
let mut schala: Box<ProgrammingLanguageInterface> = schala_gen();
let code_output = schala.evaluate_in_repl(&input.source, &EvalOptions::default());
Json(Output { text: code_output.to_string() })
}
pub fn web_main(language_generators: Vec<Box<ProgrammingLanguageInterface>>, func: PLIGenerator) {
rocket::ignite().manage(Mutex::new(func)).mount("/", routes![index, js_bundle, interpreter_input]).launch();
rocket::ignite().manage(func).mount("/", routes![index, js_bundle, interpreter_input]).launch();
}