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
41
42
43
44
use ;
/// Creates a new [`CompletableFuture`] and the associated [`CompleteHandle`] inside a scope.
///
/// An alternative API to [`create`], that while being less ergonomic is harder to deadlock (see
/// [`create`] documentation).
///
/// ```rust
/// # use future_handles::sync;
/// # async fn func() -> u32 {
/// let future = sync::scoped(|handle| {
/// func_with_callback(|res| {
/// handle.complete(res);
/// });
/// });
///
/// match future.await {
/// // The callback was invoked and the result set via the handle.
/// Ok(res) => res,
/// // The callback was never invoked, but the handle has been dropped.
/// Err(err) => panic!("Handle was dropped without setting a value")
/// }
/// # }
/// # fn func_with_callback<F>(func: F)
/// # where F: FnOnce(u32) {
/// # func(1);
/// # }
/// ```
///
/// [`create`]: super::create::create
/// [`CompletableFuture`]: super::CompletableFuture
/// [`CompleteHandle`]: super::CompleteHandle
// Doesn't execute the closure until polled for the first time.
// pub fn scoped_lazy()