Debian Codegraph @

debian/missing-sources/gio/src/test_util.rs

raw
1 // Take a look at the license at the top of the repository in the LICENSE file.
2
3 #[cfg(test)]
4 use std::sync::mpsc::{Sender, channel};
5
6 #[cfg(test)]
7 use glib::{MainContext, MainLoop};
8
9 #[cfg(test)]
10 pub fn run_async<T: Send + 'static, Q: FnOnce(Sender<T>, MainLoop) + Send + 'static>(
11 start: Q,
12 ) -> T {
13 let c = MainContext::new();
14 let l = MainLoop::new(Some(&c), false);
15 let l_clone = l.clone();
16
17 let (tx, rx) = channel();
18
19 c.spawn(async move {
20 start(tx, l_clone);
21 });
22
23 l.run();
24
25 rx.recv().unwrap()
26 }
27
28 #[cfg(test)]
29 pub fn run_async_local<T: 'static, Q: FnOnce(Sender<T>, MainLoop) + Send + 'static>(start: Q) -> T {
30 let c = MainContext::new();
31 let l = MainLoop::new(Some(&c), false);
32 let l_clone = l.clone();
33
34 let (tx, rx) = channel();
35
36 c.spawn_local(async move {
37 start(tx, l_clone);
38 });
39
40 l.run();
41
42 rx.recv().unwrap()
43 }