Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: docs/callback.md

Issue 2755073002: Update documentation for base::ResetAndReturn(Callback*) (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« base/callback_helpers.h ('K') | « base/callback_helpers.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: docs/callback.md
diff --git a/docs/callback.md b/docs/callback.md
index 6b7dd6931f5009a402696c7753c619a48ff98b62..37edad19ce0cd0ab25a9f6e28e7e14e69df5fc0a 100644
--- a/docs/callback.md
+++ b/docs/callback.md
@@ -152,6 +152,17 @@ void DoSomething(const RepeatingCallback<double(double)>& callback) {
}
```
+If running a callback could result in its own destruction (e.g., if the callback
+recipient deletes the object the callback is a member of), the callback should
+be moved before it can be safely invoked. The `base::ResetAndReturn` method
+provides this functionality.
+
+```cpp
+Foo::RunCallback() {
tzik 2017/03/17 14:01:06 nit: void Foo::RunCallback() {
michaelpg 2017/03/17 22:58:20 whoops, done
+ base::ResetAndReturn(&foo_deleter_callback_).Run();
+}
+```
+
### Passing Unbound Input Parameters
Unbound parameters are specified at the time a callback is `Run()`. They are
« base/callback_helpers.h ('K') | « base/callback_helpers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698