KDBindings icon indicating copy to clipboard operation
KDBindings copied to clipboard

Draft - Single Shot Connection

Open LeonMatthesKDAB opened this issue 3 years ago • 3 comments

A single shot connection could possibly be implemented by creating a binding that captures its own ConnectionHandle and disconnects it when the signal is emitted.

Open question: How to capture the ConnectionHandle in the slot itself?

LeonMatthesKDAB avatar Feb 02 '22 10:02 LeonMatthesKDAB

I'm a bit confused about this, don't we need a special method for single shot connection, like singleShotConnect ? that gets disconnected after emit, which could be easily implemented just by having a set flag isSingleShot in singleShotConnect and each time when emit gets called, it should check that emit was on a single shot connection and if that's the case immediately disconnects it? Don't need to get around connection handle.

phyBrackets avatar Sep 28 '23 09:09 phyBrackets

That should work as well. I was just thinking that something like this should maybe be possible:

mySignal.connect([](const auto &handle) {
    // do thing
    handle.disconnect();
});

More of a thought experiment than anything substantial. An approach like that wouldn't need another connect function and seems kind of elegantly recursive almost. It would even allow you to block the connect after it's first emitted, instead of disconnecting. It could then be unblocked again without having to reconnect. Might be useful for rate-limiting :thinking:

But it's also incompatible with the current connect function I think, so don't know if it's worth continuing down.

Introducing a singleshotConnect function definitely works as well, so that's the more likely route to go down. Though something like connectReflective would be cool, that allows you to reach your own ConnectionHandle... That might run into weird lifetime issues though, where a lambda is deleted while in use, which could get quite hairy...

Anyhow, some food for thought.

LeonMatthesKDAB avatar Oct 04 '23 07:10 LeonMatthesKDAB

The basics of reflective connections were layed out in #23, so we may want to revisit this idea :)

LeonMatthesKDAB avatar Jan 17 '24 08:01 LeonMatthesKDAB

Complete as of #70

LeonMatthesKDAB avatar Jul 05 '24 07:07 LeonMatthesKDAB