Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix interval tick #108

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 4 additions & 2 deletions src/extensions/api/substrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +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(
"chain_subscribeNewHeads",
Expand All @@ -92,6 +91,9 @@ impl SubstrateApi {
)
.await?;

// Reset the interval
interval.reset();

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