Skip to content

Commit

Permalink
fix interval tick
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci committed Oct 3, 2023
1 parent 65e9de3 commit 0a186b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/extensions/api/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ impl EthApi {
let client2 = client.clone();
tokio::spawn(async move {
let mut interval = tokio::time::interval(stale_timeout);
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Delay);

let client = client2.clone();

loop {
let run = async {
interval.reset();

// query current head
let head = client
.request("eth_getBlockByNumber", vec!["latest".into(), true.into()])
Expand All @@ -108,6 +108,9 @@ impl EthApi {
)
.await?;

// Reset the interval
interval.reset();

loop {
tokio::select! {
val = sub.next() => {
Expand Down
5 changes: 4 additions & 1 deletion src/extensions/api/substrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ impl SubstrateApi {

tokio::spawn(async move {
let mut interval = tokio::time::interval(stale_timeout);
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Delay);

let client = client.clone();

loop {
let run = async {
interval.reset();

let mut sub = client
.subscribe(
Expand All @@ -92,6 +92,9 @@ impl SubstrateApi {
)
.await?;

// Reset the interval
interval.reset();

loop {
tokio::select! {
val = sub.next() => {
Expand Down

0 comments on commit 0a186b7

Please sign in to comment.