v1
This commit is contained in:
@@ -28,6 +28,7 @@ struct TestDispatcherState {
|
||||
time: Duration,
|
||||
is_main_thread: bool,
|
||||
next_id: TestDispatcherId,
|
||||
allow_parking: bool,
|
||||
}
|
||||
|
||||
impl TestDispatcher {
|
||||
@@ -40,6 +41,7 @@ impl TestDispatcher {
|
||||
time: Duration::ZERO,
|
||||
is_main_thread: true,
|
||||
next_id: TestDispatcherId(1),
|
||||
allow_parking: false,
|
||||
};
|
||||
|
||||
TestDispatcher {
|
||||
@@ -66,7 +68,7 @@ impl TestDispatcher {
|
||||
self.state.lock().time = new_now;
|
||||
}
|
||||
|
||||
pub fn simulate_random_delay(&self) -> impl Future<Output = ()> {
|
||||
pub fn simulate_random_delay(&self) -> impl 'static + Send + Future<Output = ()> {
|
||||
pub struct YieldNow {
|
||||
count: usize,
|
||||
}
|
||||
@@ -75,6 +77,7 @@ impl TestDispatcher {
|
||||
type Output = ();
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
|
||||
eprintln!("self.count: {}", self.count);
|
||||
if self.count > 0 {
|
||||
self.count -= 1;
|
||||
cx.waker().wake_by_ref();
|
||||
@@ -93,6 +96,14 @@ impl TestDispatcher {
|
||||
pub fn run_until_parked(&self) {
|
||||
while self.poll() {}
|
||||
}
|
||||
|
||||
pub fn parking_allowed(&self) -> bool {
|
||||
self.state.lock().allow_parking
|
||||
}
|
||||
|
||||
pub fn allow_parking(&self) {
|
||||
self.state.lock().allow_parking = true
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for TestDispatcher {
|
||||
|
||||
Reference in New Issue
Block a user