ARMmbed / mbed-events

DEPRECATED! This project has moved to mbed-os
https://github.com/ARMmbed/mbed-os/tree/master/events
Apache License 2.0
11 stars 6 forks source link

Add callback operations to event class #17

Closed geky closed 7 years ago

geky commented 7 years ago

This adds a C++ style function API that allows the event class to be easily passed as an argument to existing callback based APIs:

void Event<void(args...)>::call(args...)
void Event<void(args...)>::operator()(args...)
static void Event<void(args...)>::thunk(void *, args...)

The previous discussion on this subject can be found here: https://github.com/ARMmbed/mbed-events/pull/15

In reviewing the pr, don't think there are problems with introducing the callable interface. This design is compatible with passing function objects by both reference and by value, and adds convenient integration with existing C and C++ callback APIs without creating a special case for mbed OS.

There is a concern that this interface would encourage users to use the unclear event() syntax. But this can be discouraged through documentation.

cc @pan-

geky commented 7 years ago

Given the experimental nature of this repository, I'm going to go ahead and merge this pr. We can deprecate the callback operations at a later version if we find them to be impractical.