Skip to content

Commit 7265874

Browse files
committed
refactor: asyncronous memoizing :)
1 parent 2c85030 commit 7265874

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/tasks/submit/prep.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use signet_constants::SignetSystemConstants;
1616
use signet_sim::BuiltBlock;
1717
use signet_types::{SignRequest, SignResponse};
1818
use signet_zenith::BundleHelper;
19-
use std::sync::OnceLock;
2019
use tracing::Instrument;
2120

2221
/// Preparation logic for transactions issued to the host chain by the
@@ -35,8 +34,8 @@ pub struct SubmitPrep<'a> {
3534
constants: SignetSystemConstants,
3635

3736
// Memoized quincey request and response
38-
sig_request: OnceLock<SignRequest>,
39-
quincey_resp: OnceLock<SignResponse>,
37+
sig_request: std::sync::OnceLock<SignRequest>,
38+
quincey_resp: tokio::sync::OnceCell<SignResponse>,
4039
}
4140

4241
impl<'a> SubmitPrep<'a> {
@@ -78,12 +77,12 @@ impl<'a> SubmitPrep<'a> {
7877

7978
/// Get the quincey signature response for the block.
8079
async fn quincey_resp(&self) -> eyre::Result<&SignResponse> {
81-
if let Some(resp) = self.quincey_resp.get() {
82-
return Ok(resp);
83-
}
84-
85-
let sig = self.quincey.get_signature(self.sig_request()).await?;
86-
Ok(self.quincey_resp.get_or_init(|| sig))
80+
self.quincey_resp
81+
.get_or_try_init(|| async {
82+
let sig_request = self.sig_request();
83+
self.quincey.get_signature(sig_request).await
84+
})
85+
.await
8786
}
8887

8988
/// Get the signature components from the response.

0 commit comments

Comments
 (0)