Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question: how to manage lifetime of lambdas #27

Open
geiseri opened this issue Apr 1, 2020 · 2 comments
Open

question: how to manage lifetime of lambdas #27

geiseri opened this issue Apr 1, 2020 · 2 comments
Labels

Comments

@geiseri
Copy link

geiseri commented Apr 1, 2020

I am moving from Qt signals/slots and I use this pattern all over the place:

connect(src, &Source::method, [](...) {...});

The issue I have is that in these cases I do not wish to manage the lifetime of the callback. Of course, since nano-signal-slot doesn't manage the lifetime of a callback this fails to compile:

somesignal->connect([](...){...});

Do you have a suggestion that can tie callback to the lifetime of the somesignal object? For the life of me I cannot figure out a way to track the lifetime without the signal taking ownership.

@geiseri
Copy link
Author

geiseri commented Apr 3, 2020

https://github.com/palacaze/sigslot#automatic-slot-lifetime-tracking looks like an interesting approach.

@NoAvailableAlias
Copy link
Owner

Hello, in order for nano-signal-slot to support arbitrary slot disconnect, the connect would either need to return a disconnect object or it would need to consume a disconnect object.

Returning disconnect objects "usually" results in a discard by most library clients in which case void is better than [[nodiscard]]. Consuming a disconnect object would require the connections to store additional data which may or may not be used by all clients. This violates the "don't pay for what you don't use" goal of nano-signal-slot.

The only alternative is to externalize this cost to the client and force them to maintain their own disconnect scheme for non-Observer derived slots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants