full cache lifecycle

This commit is contained in:
Cadey Ratio 2019-12-18 12:39:47 +00:00
parent 617ca6066e
commit 9219e0b364
1 changed files with 17 additions and 3 deletions

View File

@ -40,9 +40,10 @@ fn begin(cache: State<Cache>, msg: Json<battlesnake::SnakeRequest>) -> Json<batt
path: path,
};
if let Some(x) = cache.lock().expect("wanted cache to be unlockable").get_mut(&msg.game.id) {
*x = gs;
};
cache
.lock()
.expect("wanted to lock cache")
.insert(msg.game.id.clone(), gs);
Json(battlesnake::StartResponse{
color: "#5ce8c3".to_string(),
@ -71,6 +72,19 @@ fn find_path(
}
}
#[post("/end", format = "json", data = "<msg>")]
fn end(
cache_state: State<Cache>,
msg: Json<battlesnake::SnakeRequest>,
) -> String {
cache_state
.lock()
.expect("wanted cache to be lockable")
.remove(&msg.game.id);
"OK".to_string()
}
#[post("/move", format = "json", data = "<msg>")]
fn make_move(
cache_state: State<Cache>,