Skip to content

Commit

Permalink
Release 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexheretic committed Dec 16, 2024
1 parent e797531 commit ab935e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v1.3.0
* Add `sleep_until`, `SpinSleeper::sleep_until`.

# v1.2.1
* Windows: Update _windows-sys_ to 0.59.

Expand Down
15 changes: 7 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,17 @@ impl SpinSleeper {
}
}

/// Puts the [current thread to sleep](fn.native_sleep.html) for the duration less the
/// Puts the [current thread to sleep](fn.native_sleep.html) for the `duration` less the
/// configured native accuracy. Then spins until the specified duration has elapsed.
pub fn sleep(self, duration: Duration) {
let deadline = Instant::now() + duration;
self.spin_sleep(duration, deadline);
}

/// Puts the [current thread to sleep](fn.native_sleep.html) until deadline less
/// the configured native accuracy. Then spins until the specified instant is reached.
/// Puts the [current thread to sleep](fn.native_sleep.html) until the `deadline` less
/// the configured native accuracy. Then spins until the specified deadline is reached.
pub fn sleep_until(self, deadline: Instant) {
let start = Instant::now();
let duration = deadline.saturating_duration_since(start);
let duration = deadline.saturating_duration_since(Instant::now());
self.spin_sleep(duration, deadline);
}

Expand All @@ -188,7 +187,7 @@ impl SpinSleeper {
}
}

/// Puts the [current thread to sleep](fn.native_sleep.html) for the duration less the
/// Puts the [current thread to sleep](fn.native_sleep.html) for the `duration` less the
/// default native accuracy. Then spins until the specified duration has elapsed.
///
/// Convenience function for `SpinSleeper::default().sleep(duration)`. Can directly take the
Expand All @@ -197,8 +196,8 @@ pub fn sleep(duration: Duration) {
SpinSleeper::default().sleep(duration);
}

/// Puts the [current thread to sleep](fn.native_sleep.html) until instant less
/// the configured native accuracy. Then spins until the specified instant is reached.
/// Puts the [current thread to sleep](fn.native_sleep.html) until the `deadline` less
/// the configured native accuracy. Then spins until the specified deadline is reached.
///
/// Convenience function for `SpinSleeper::default().sleep_until(instant)`. Can directly take
/// the place of `thread::sleep_until`.
Expand Down

0 comments on commit ab935e3

Please sign in to comment.