zebra_consensus/
primitives.rs1use tokio::sync::oneshot::error::RecvError;
4
5use crate::BoxError;
6
7pub mod ed25519;
8pub mod groth16;
9pub mod halo2;
10pub mod redjubjub;
11pub mod redpallas;
12pub mod sapling;
13
14const MAX_BATCH_SIZE: usize = 64;
16
17const MAX_BATCH_LATENCY: std::time::Duration = std::time::Duration::from_millis(100);
19
20pub async fn spawn_fifo_and_convert<
23 E: 'static + std::error::Error + Into<BoxError> + Sync + Send,
24 F: 'static + FnOnce() -> Result<(), E> + Send,
25>(
26 f: F,
27) -> Result<(), BoxError> {
28 spawn_fifo(f)
29 .await
30 .map_err(|_| {
31 "threadpool unexpectedly dropped response channel sender. Is Zebra shutting down?"
32 })?
33 .map_err(BoxError::from)
34}
35
36pub async fn spawn_fifo<T: 'static + Send, F: 'static + FnOnce() -> T + Send>(
38 f: F,
39) -> Result<T, RecvError> {
40 let (rsp_tx, rsp_rx) = tokio::sync::oneshot::channel();
43
44 rayon::spawn_fifo(move || {
45 let _ = rsp_tx.send(f());
46 });
47
48 rsp_rx.await
49}