Skip to content

Commit 34dacac

Browse files
committed
Adding in documentation
1 parent b98dc38 commit 34dacac

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/webcore/promise.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use futures::unsync::oneshot::channel;
1010
use super::promise_future::PromiseFuture;
1111

1212

13+
/// This is used to cleanup the [`done`](struct.Promise.html#method.done) callback.
1314
///
15+
/// See the documentation for [`done`](struct.Promise.html#method.done) for more information.
1416
#[derive( Debug, Clone )]
1517
pub struct DoneHandle {
1618
callback: Value,
@@ -95,12 +97,22 @@ impl Promise {
9597
///
9698
/// The `callback` is guaranteed to be called asynchronously even if the `Promise` is already succeeded / failed.
9799
///
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.
99111
///
100112
/// # Examples
101113
///
102114
/// ```rust
103-
/// promise.done(|result| {
115+
/// let handle = promise.done(|result| {
104116
/// match result {
105117
/// Ok(success) => { ... },
106118
/// Err(error) => { ... },

0 commit comments

Comments
 (0)