Thanks for the reply Ben!
If this is the case, I would maintain a state inside the callback and check the state to decide if the callback just doing nothing and return , or continue its planned action.
I do have another question regarding to pp::CompletionCallback.
1. when using it with pp::API(…, callback),
in this case, CallOnMainThread (delay, callback), usually the ‘callback’ is create by:
callback = CompletionCallbackFactory::NewCallback(&my_method).
do I need to do something to delete this ‘callback’ object,
after ‘my_method’ being called, or the pp::API(…,callback) should take care of it already?
in another word, for me as a user, I just need ‘new' the callback, pass it into pp:API(…, callback), then don’t worry free the memory at all?
2. I want to use pp:CompletionCallback by my own 'Class A' to provide a public method for other 'Class B' to use, by pass-in a ‘method' to be called after Class A did something.
here is the example:
Class A {
public:
… …
int offered_service (..., pp::CompletionCallback &cb) {
a_cb = cb;
… ...
}
~A () {
/* do I need to delete ‘a_cb’ when this object be freed???*/
}
private:
… ...
pp:CompletionCallback *a_cb; // Class A remember the CB pointer, will call CB->run() after service done.
… …
void do_service (…) {
… ...
a_cb->Run(result);
}
}
say another 'class B' register a method by:
a->offered_service (…, B_cb_Factory.NewCallback(&B::method));
my question is, I guess 2 ways to free CB memory:
(1), Class B can free the memory by calling B_cb_Factory.CancelAll()
(2). Class A can delete ‘a_cb’ since it has the pointer to the CB.
did I get it wrong? and,
what’s the best practice to take care deleting the CompletionCallback object?
thanks alot
-Yong