Skip to content

Commit

Permalink
fix interval tick (#108)
Browse files Browse the repository at this point in the history
* fix interval tick

* fmt
  • Loading branch information
ermalkaleci authored Oct 3, 2023
1 parent ba32a53 commit c5fe1c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/extensions/api/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,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 @@ -97,6 +97,9 @@ impl EthApi {
.subscribe("eth_subscribe", ["newHeads".into()].into(), "eth_unsubscribe")
.await?;

// Reset the interval
interval.reset();

loop {
tokio::select! {
val = sub.next() => {
Expand Down
6 changes: 4 additions & 2 deletions src/extensions/api/substrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,19 @@ 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("chain_subscribeNewHeads", [].into(), "chain_unsubscribeNewHeads")
.await?;

// Reset the interval
interval.reset();

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

0 comments on commit c5fe1c8

Please sign in to comment.