-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from communityvi/dont-capture-lifetimes
Stop capturing the MockableClock lifetimes in the futures returned from their methods
- Loading branch information
Showing
11 changed files
with
147 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
[workspace] | ||
members = ["async-time-mock*"] | ||
members = [ | ||
"async-time-mock-async-std", | ||
"async-time-mock-core", | ||
"async-time-mock-smol", | ||
"async-time-mock-tokio", | ||
] | ||
resolver = "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::TimeHandlerGuard; | ||
#[cfg(feature = "mock")] | ||
use async_time_mock_core::TimerListener; | ||
use pin_project::pin_project; | ||
use std::fmt::Debug; | ||
use std::future::Future; | ||
use std::pin::Pin; | ||
use std::task::{ready, Context, Poll}; | ||
|
||
#[pin_project(project = SleepProjection)] | ||
#[derive(Debug)] | ||
pub enum Sleep { | ||
Real(#[pin] tokio::time::Sleep), | ||
#[cfg(feature = "mock")] | ||
Mock(#[pin] TimerListener), | ||
} | ||
|
||
impl From<tokio::time::Sleep> for Sleep { | ||
fn from(sleep: tokio::time::Sleep) -> Self { | ||
Self::Real(sleep) | ||
} | ||
} | ||
|
||
#[cfg(feature = "mock")] | ||
impl From<TimerListener> for Sleep { | ||
fn from(listener: TimerListener) -> Self { | ||
Self::Mock(listener) | ||
} | ||
} | ||
|
||
impl Future for Sleep { | ||
type Output = TimeHandlerGuard; | ||
|
||
fn poll(self: Pin<&mut Self>, context: &mut Context<'_>) -> Poll<Self::Output> { | ||
let this = self.project(); | ||
|
||
use SleepProjection::*; | ||
match this { | ||
Real(sleep) => { | ||
ready!(sleep.poll(context)); | ||
Poll::Ready(TimeHandlerGuard::Real) | ||
} | ||
#[cfg(feature = "mock")] | ||
Mock(listener) => { | ||
let guard = ready!(listener.poll(context)); | ||
Poll::Ready(guard.into()) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters