1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::future::Future;
use crate::handles::SqlResult;
pub trait Sleep {
type Poll: Future;
fn next_poll(&mut self) -> Self::Poll;
}
impl<S, F> Sleep for S
where
S: FnMut() -> F,
F: Future,
{
type Poll = F;
fn next_poll(&mut self) -> Self::Poll {
(self)()
}
}
pub async fn wait_for<F, O>(mut f: F, sleep: &mut impl Sleep) -> SqlResult<O>
where
F: FnMut() -> SqlResult<O>,
{
let mut ret = (f)();
while matches!(ret, SqlResult::StillExecuting) {
sleep.next_poll().await;
ret = (f)();
}
ret
}