将分离状态序列化移入阻塞任务

避免在异步执行器线程同步格式化大型 separation state。
This commit is contained in:
2026-09-12 14:48:00 +08:00
parent 9788087271
commit 398edd6e86
@@ -47,9 +47,12 @@ pub async fn write_separation_state(path: PathBuf, state: &SeparationState) -> R
app_log!("ui_separation.error stage=state_write reason=schema_mismatch");
return Err("不支持的 separation state schema".to_string());
}
let state = serde_json::to_vec_pretty(state)
.map_err(|error| format!("序列化 separation state 失败:{error}"))?;
tokio::task::spawn_blocking(move || write_separation_state_blocking(&path, &state))
let owned = state.clone();
tokio::task::spawn_blocking(move || {
let bytes = serde_json::to_vec_pretty(&owned)
.map_err(|error| format!("序列化 separation state 失败:{error}"))?;
write_separation_state_blocking(&path, &bytes)
})
.await
.map_err(|error| format!("写入 separation state 任务失败:{error}"))?
}