Compare commits

...

2 Commits

Author SHA1 Message Date
peilun-conflux
992deb0979
Merge 07704fedc9 into 0c493880ee 2024-11-09 13:37:33 +08:00
Peilun Li
07704fedc9 fix: wait for async storage to complete before receiving the result. 2024-10-30 18:51:45 +08:00

View File

@ -1,7 +1,7 @@
#[macro_use]
extern crate tracing;
use anyhow::bail;
use anyhow::{anyhow, bail};
use shared_types::{
Chunk, ChunkArray, ChunkArrayWithProof, DataRoot, FlowProof, FlowRangeProof, Transaction,
};
@ -140,17 +140,21 @@ impl Store {
let store = self.store.clone();
let (tx, rx) = oneshot::channel();
self.executor.spawn_blocking(
move || {
// FIXME(zz): Not all functions need `write`. Refactor store usage.
let res = f(&*store);
self.executor
.spawn_blocking_handle(
move || {
// FIXME(zz): Not all functions need `write`. Refactor store usage.
let res = f(&*store);
if tx.send(res).is_err() {
error!("Unable to complete async storage operation: the receiver dropped");
}
},
WORKER_TASK_NAME,
);
if tx.send(res).is_err() {
error!("Unable to complete async storage operation: the receiver dropped");
}
},
WORKER_TASK_NAME,
)
.ok_or(anyhow!("Unable to spawn async storage work"))?
.await
.map_err(|e| anyhow!("join error: e={:?}", e))?;
rx.await
.unwrap_or_else(|_| bail!(error::Error::Custom("Receiver error".to_string())))