--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAJtUDMwF64o7BiV2g83eEazSqEhkuY2-73NTfLRgtesXFWvaMQ%40mail.gmail.com.
It seems useful to be able to distinguish between an unbound and bound callback. I suppose one possibility would be to use Optional instead, but that would be a pretty major change (and would also differ from the behavior of things like std::function).As an alternative, there's base::BindOnce(&base::DoNothing). Does that work?
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAAHOzFAm0p14d0Q5PEAwbnnFagr7ZpdW7CKXRPZQ_hcZ2HmNMA%40mail.gmail.com.
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAAHOzFCcfJv0mimGucDrZgL6N7aA27taXr6Bo6Bi1haF8D2C4A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CA%2BapAgH9rRuc_-JdVDKs_o_5DGLLn8vWJ0s1fS_poJTmJ%2BgtVQ%40mail.gmail.com.
My mental model is that a OnceCallback is like a std::unique_ptr<BoundFunctionState> and a RepeatingCallback is a like a std::scoped_refptr<BoundFunctionState>. From this point of view it's natural and consistent that the default constructor creates a null callback.On 16 June 2017 at 16:25, Ken Rockot <roc...@chromium.org> wrote:(and you would probably break quite a lot of code in subtle ways if you tried changing that at this point)On Fri, Jun 16, 2017 at 12:23 AM, Ken Rockot <roc...@chromium.org> wrote:All of our callback types default to a null state.On Fri, Jun 16, 2017 at 12:20 AM, Peter Kasting <pkas...@chromium.org> wrote:On Fri, Jun 16, 2017 at 12:14 AM, Daniel Cheng <dch...@chromium.org> wrote:Sorry, I was imprecise with my terminology. A default constructed Closure (or OnceClosure) is "null": that is, the functor doesn't point to anything. Calling Run() on a null Closure/OneClosure will crash, rather than silently no-op.On Fri, Jun 16, 2017 at 12:03 AM Peter Kasting <pkas...@chromium.org> wrote:On Thu, Jun 15, 2017 at 4:51 PM, Daniel Cheng <dch...@chromium.org> wrote:It seems useful to be able to distinguish between an unbound and bound callback. I suppose one possibility would be to use Optional instead, but that would be a pretty major change (and would also differ from the behavior of things like std::function).As an alternative, there's base::BindOnce(&base::DoNothing). Does that work?I'm confused. What is an "unbound callback"? I thought that meant "a callback with some unbound params", but if you just say OnceClosure(), you're not claiming there are any params -- indeed, the definition of a closure is "a callback with no unbound params". So what's unbound?I thought it was the case that for things like Closure(), you could create the object and run it. It seems very surprising if Closure() lets you run it but OnceClosure() does not.PKOK, so that clarifies the terminology. I'm still unclear on why the default object is not a no-op functor rather than a null functor. It sounds like you're saying I'm wrong about Closure() doing this. Does Callback() do this?
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAHixhFpUSGyV3u-AJo1EYrXRrU9-L%3DS3Vm7yB5bKXoS5Hw7dkw%40mail.gmail.com.
Do we have a history of problems with null Callbacks? Or would you just rather avoid the if non-null check before running in a few places?
We sure need to keep the operator bool() for empty callbacks but I can't immediately think of reasons why no-op when running null callback would be problematic. But I also don't see why the status quo is problematic either.
As for the OP, we have base::DoNothing in bind_helpers.h (if that wasn't obvious, then perhaps it's a documentation update that's needed?)
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAAHOzFDZVgEmdmD-%2Bhz_a9CnvA%3D19RV1jTXz414Ay0uxYAshYw%40mail.gmail.com.
Do we have a history of problems with null Callbacks?
Or would you just rather avoid the if non-null check before running in a few places?
As for the OP, we have base::DoNothing in bind_helpers.h (if that wasn't obvious, then perhaps it's a documentation update that's needed?)
On Tue, Jan 30, 2018 at 11:36 PM, Gabriel Charette <g...@chromium.org> wrote:Do we have a history of problems with null Callbacks?
Well, I seem to. Every six months or so I run into crashes the turn out to be because I wrote code passing a default-constructed callback and expecting it to do nothing when run. I don't know if anyone else has such issues, though. As mentioned earlier in this thread, I wasn't the only person who thought things would work this way, but I can't speak to how many others actually seem to write code depending on it.
Or would you just rather avoid the if non-null check before running in a few places?
Actually I suspect we could save quite a number if "if (!null)" checks before calling Run()... that might be a good reason to do this.
As for the OP, we have base::DoNothing in bind_helpers.h (if that wasn't obvious, then perhaps it's a documentation update that's needed?)
Sadly DoNothing() only works for Closures; if the signature is anything else, you need to use Bind with a no-op lambda of the right signature.I wonder if there's a clever way to use variadic templates or something to write a DoNothing that can automatically be passed to functions expecting any signature of Callback.
PK
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAAHOzFAtgeeRf0wUZ2OJfqbz%3D45fCMUcc%2BVhJEQpVDeUN9jgjA%40mail.gmail.com.
OnceClosure closure = noop_callback;
closure(); // This is safe
PK
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CACuR13dnYWnvFCBROvNqxEk2zo2%2BeKyEguLnrPghKhuMa5_pXg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAH%3DT95QDkv2D2NCFwZKu%3DzCTisiNaKQmKr%3D7rOpdw7X7nVG98g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAEhBV%3DvQi4AkGWoCifiLzAWv%3DquSfFXXFtYQf%3DaEedTnArrO0Q%40mail.gmail.com.
On Wed, Jan 31, 2018 at 2:58 AM, Peter Kasting <pkas...@chromium.org> wrote:I wonder if there's a clever way to use variadic templates or something to write a DoNothing that can automatically be passed to functions expecting any signature of Callback.Yes, this could be done. Though it's still kinda thorny insofar as non-void-returning functions must produce a value.
I wouldn't mind something like this if base/ owners thought it was okay, but I'm not sure I'd want it to be the default behavior of callbacks.
On Wed, Jan 31, 2018 at 7:35 AM, Jeremy Roman <jbr...@chromium.org> wrote:On Wed, Jan 31, 2018 at 2:58 AM, Peter Kasting <pkas...@chromium.org> wrote:I wonder if there's a clever way to use variadic templates or something to write a DoNothing that can automatically be passed to functions expecting any signature of Callback.Yes, this could be done. Though it's still kinda thorny insofar as non-void-returning functions must produce a value.I wouldn't mind something like this if base/ owners thought it was okay, but I'm not sure I'd want it to be the default behavior of callbacks.I think DoNothing doesn't really make sense conceptually for callbacks that return a value, anyway. Returning a value is doing something. And I've never run into a case where it's reasonable to pass a "do nothing" (in concept) callback when it's supposed to return a value. Whereas "do nothing" is frequently meaningful for "give me a callback that I should notify when X happens", when the caller doesn't care about X happening (e.g. because we're in a test). Those sorts of callbacks don't return values.
namespace base {
enum noop_callback_t {noop_callback};
class OnceCallback {
public:
OnceCallback(noop_callback_t);
};
} // namespace base
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAJTZ7L%2BkBAce8SYViNATWHoyF8W0DjV-xXshFi6sBFYh8rvTEw%40mail.gmail.com.
That would work.Would keep OnceClosure becomes null after being ran property.Default constructor would still be a null callback.But we have a trivial way to build a noop_callback.PS: I lost track, what's the use case for no-op callback again?!
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAJTZ7LJ0MJ%2B40oLTMz3E__4WurcOqcP7rMQqUfeyHy%2Bcses7Ow%40mail.gmail.com.
On Thu, Feb 1, 2018 at 1:55 PM Gabriel Charette <g...@chromium.org> wrote:That would work.Would keep OnceClosure becomes null after being ran property.Default constructor would still be a null callback.But we have a trivial way to build a noop_callback.PS: I lost track, what's the use case for no-op callback again?!The primary use case that I've seen is for tests to supply a callback that can be run to production code that expects the callback to be non-null. The alternative is to add the conditional in the production code just for the test, which is unappealing.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAJTZ7LJaXzBmnNsbb1M%3Da76PE8KE1DPsWWijRtaYAeA6mFG2Cg%40mail.gmail.com.
I'll see if I can implement this locally.
On Wed, Jan 31, 2018 at 1:24 PM, Peter Kasting <pkas...@chromium.org> wrote:I'll see if I can implement this locally.Update: I'm in the process of implementing the version that looks like this:Old: base::Bind(&base::DoNothing)New: base::DoNothing()
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAAHOzFBriO2onQgAQW%2BoM-nkak%2BZC6BPE9Y7eKWJ5uKg%3DTdy%2BA%40mail.gmail.com.