windows_future/
get.rs

1use super::*;
2
3impl IAsyncAction {
4    /// Waits for the `IAsyncAction` to finish.
5    pub fn get(&self) -> Result<()> {
6        if self.Status()? == AsyncStatus::Started {
7            let (_waiter, signaler) = Waiter::new()?;
8            self.SetCompleted(&AsyncActionCompletedHandler::new(move |_, _| {
9                // This is safe because the waiter will only be dropped after being signaled.
10                unsafe {
11                    signaler.signal();
12                }
13                Ok(())
14            }))?;
15        }
16        self.GetResults()
17    }
18}
19
20impl<T: RuntimeType> IAsyncOperation<T> {
21    /// Waits for the `IAsyncOperation<T>` to finish.
22    pub fn get(&self) -> Result<T> {
23        if self.Status()? == AsyncStatus::Started {
24            let (_waiter, signaler) = Waiter::new()?;
25            self.SetCompleted(&AsyncOperationCompletedHandler::new(move |_, _| {
26                // This is safe because the waiter will only be dropped after being signaled.
27                unsafe {
28                    signaler.signal();
29                }
30                Ok(())
31            }))?;
32        }
33        self.GetResults()
34    }
35}
36
37impl<P: RuntimeType> IAsyncActionWithProgress<P> {
38    /// Waits for the `IAsyncActionWithProgress<P>` to finish.
39    pub fn get(&self) -> Result<()> {
40        if self.Status()? == AsyncStatus::Started {
41            let (_waiter, signaler) = Waiter::new()?;
42            self.SetCompleted(&AsyncActionWithProgressCompletedHandler::new(
43                move |_, _| {
44                    // This is safe because the waiter will only be dropped after being signaled.
45                    unsafe {
46                        signaler.signal();
47                    }
48                    Ok(())
49                },
50            ))?;
51        }
52        self.GetResults()
53    }
54}
55
56impl<T: RuntimeType, P: RuntimeType> IAsyncOperationWithProgress<T, P> {
57    /// Waits for the `IAsyncOperationWithProgress<T, P>` to finish.
58    pub fn get(&self) -> Result<T> {
59        if self.Status()? == AsyncStatus::Started {
60            let (_waiter, signaler) = Waiter::new()?;
61            self.SetCompleted(&AsyncOperationWithProgressCompletedHandler::new(
62                move |_, _| {
63                    // This is safe because the waiter will only be dropped after being signaled.
64                    unsafe {
65                        signaler.signal();
66                    }
67                    Ok(())
68                },
69            ))?;
70        }
71        self.GetResults()
72    }
73}