@@ -10,7 +10,9 @@ use futures::unsync::oneshot::channel;
10
10
use super :: promise_future:: PromiseFuture ;
11
11
12
12
13
+ /// This is used to cleanup the [`done`](struct.Promise.html#method.done) callback.
13
14
///
15
+ /// See the documentation for [`done`](struct.Promise.html#method.done) for more information.
14
16
#[ derive( Debug , Clone ) ]
15
17
pub struct DoneHandle {
16
18
callback : Value ,
@@ -95,12 +97,22 @@ impl Promise {
95
97
///
96
98
/// The `callback` is guaranteed to be called asynchronously even if the `Promise` is already succeeded / failed.
97
99
///
98
- /// If the `Promise` never succeeds / fails then the `callback` will never be called, and it will leak memory.
100
+ /// If the `Promise` never succeeds / fails then the `callback` will never be called.
101
+ ///
102
+ /// This method returns a [`DoneHandle`](struct.DoneHandle.html). When the [`DoneHandle`](struct.DoneHandle.html)
103
+ /// is dropped it will drop the `callback` and the `callback` will never be called. This is useful if you are
104
+ /// no longer interested in the `Promise`'s result.
105
+ ///
106
+ /// But if you *are* interested in the `Promise`'s result, then you need to make sure to keep the handle alive
107
+ /// until after the callback is called.
108
+ ///
109
+ /// Dropping the [`DoneHandle`](struct.DoneHandle.html) does ***not*** cancel the `Promise`, because promises
110
+ /// do not support cancellation.
99
111
///
100
112
/// # Examples
101
113
///
102
114
/// ```rust
103
- /// promise.done(|result| {
115
+ /// let handle = promise.done(|result| {
104
116
/// match result {
105
117
/// Ok(success) => { ... },
106
118
/// Err(error) => { ... },
0 commit comments