got api working ish, I need to clean this code up a lot
This commit is contained in:
+34
-4
@@ -1,10 +1,38 @@
|
||||
use std::fs;
|
||||
use std::collections::HashMap;
|
||||
use std::
|
||||
{
|
||||
fs,
|
||||
thread,
|
||||
collections::HashMap,
|
||||
sync::{Arc, Mutex, mpsc},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::task;
|
||||
use warp::Filter;
|
||||
|
||||
mod parsing;
|
||||
mod character;
|
||||
mod config;
|
||||
mod api;
|
||||
|
||||
fn main() {
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let (tx,rx) = mpsc::channel();
|
||||
let mut data_to_send = Arc::new(Mutex::new(api::Data_to_send
|
||||
{
|
||||
action_type: "initialise".to_string(),
|
||||
content: "".to_string(),
|
||||
character: "".to_string(),
|
||||
}));
|
||||
|
||||
let data = Arc::clone(&data_to_send);
|
||||
let tx_clone = tx.clone();
|
||||
// Spawn a thread for warp
|
||||
tokio::spawn(
|
||||
async move {
|
||||
api::api_process(data, tx_clone).await;
|
||||
});
|
||||
println!("and continue");
|
||||
let mut characters = HashMap::<String, character::Character>::new();
|
||||
let file_contents: String = fs::read_to_string("stories/story.ha").unwrap();
|
||||
// Split the file contents into tokens
|
||||
@@ -12,7 +40,9 @@ fn main() {
|
||||
.split_whitespace()
|
||||
.collect();
|
||||
// Run the parsing process
|
||||
match parsing::token_parse(&tokens, &mut characters) {
|
||||
let data_clone = Arc::clone(&data_to_send);
|
||||
match parsing::token_parse(&tokens, &mut characters, data_clone, &rx).await
|
||||
{
|
||||
Ok(()) => println!("Program exited successfully"),
|
||||
Err(error) => println!("{}", error),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user