Skip to content

Commit 2f4a0a1

Browse files
authored
Merge pull request #380 from nervosnetwork/change-interval-init-behavior
chore: bump to 0.6.4
2 parents dcd3fe3 + 0d87b0f commit 2f4a0a1

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## tentacle 0.6.4
2+
3+
## Feature
4+
- Make `runtime::Interval` behavior same as tokio interval(#379)
5+
16
## tentacle 0.6.3
27

38
## Bug Fix

tentacle/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tentacle"
3-
version = "0.6.3"
3+
version = "0.6.4"
44
license = "MIT"
55
description = "Minimal implementation for a multiplexed p2p network framework."
66
authors = ["piaoliu <driftluo@foxmail.com>", "Nervos Core Dev <dev@nervos.org>"]

tentacle/src/runtime/generic_timer.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ pub struct Interval {
1414
}
1515

1616
impl Interval {
17+
/// Same as tokio::time::interval
1718
pub fn new(period: Duration) -> Self {
19+
Self::new_at(Duration::ZERO, period)
20+
}
21+
22+
/// Same as tokio::time::interval_at
23+
pub fn new_at(start_since_now: Duration, period: Duration) -> Self {
1824
Self {
19-
delay: Delay::new(period),
25+
delay: Delay::new(start_since_now),
2026
period,
2127
}
2228
}

tentacle/src/runtime/tokio_runtime.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ mod time {
3333
pub struct Interval(Inner);
3434

3535
impl Interval {
36+
/// Same as tokio::time::interval
3637
pub fn new(period: Duration) -> Self {
37-
Self(inner_interval(Instant::now() + period, period))
38+
Self::new_at(Duration::ZERO, period)
39+
}
40+
41+
/// Same as tokio::time::interval_at
42+
pub fn new_at(start_since_now: Duration, period: Duration) -> Self {
43+
Self(inner_interval(Instant::now() + start_since_now, period))
3844
}
3945

4046
pub fn set_missed_tick_behavior(&mut self, behavior: MissedTickBehavior) {

0 commit comments

Comments
 (0)