1
Fork 0

possibly concurrent turtle updates

This commit is contained in:
Andy Killorin 2023-12-22 10:59:13 -06:00
parent 8660daad1d
commit c5499b0277
Signed by: ank
GPG key ID: B6241CA3B552BCA4
2 changed files with 3 additions and 3 deletions

View file

@ -292,14 +292,14 @@ impl TurtleCommander {
pub(crate) async fn process_turtle_update(
id: u32,
state: &mut LiveState,
state: &LiveState,
update: TurtleUpdate,
) -> anyhow::Result<TurtleCommand> {
let mut turtle = state
.turtles
.get(id as usize)
.context("nonexisting turtle")?.write().await;
let world = &mut state.world;
let world = &state.world;
if turtle.pending_update {
turtle.pending_update = false;

View file

@ -150,7 +150,7 @@ pub(crate) async fn command(
State(state): State<SharedControl>,
Json(req): Json<turtle::TurtleUpdate>,
) -> Json<turtle::TurtleCommand> {
let mut state = &mut state.write().await;
let mut state = &mut state.read().await;
if id as usize > state.turtles.len() {
return Json(turtle::TurtleCommand::Update);