full cache lifecycle
This commit is contained in:
parent
617ca6066e
commit
9219e0b364
20
src/main.rs
20
src/main.rs
|
@ -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>,
|
||||
|
|
Loading…
Reference in New Issue