Conversation
I'm currently busy on other Snap projects and only have very limited time to review external djinni PRs. But I can raise this with my colleagues and see if there is someone willing to help drive this. If we are going to support cancellation, I would rather it to be available across the board and does not require a separate class. |
Sounds good. I would much appreciate if you'd let me know either way - if you don't find someone that's also important to know, so I can focus on rolling our own implementation for my project. |
I talked to a few people but it seems everyone is busy on higher priority tasks. |
Okay, thanks for letting me know 👍 I'll redirect my efforts to an internal implementation then. I'll leave it up to you whether to keep this open for future reference or just close it, however you like. |
In my project we would greatly benefit from having futures support cancellation requests.
The code in this PR is just a rough outline showing my approach, it is incomplete and untested. The goal is to have cancellation bridged between languages as well (ie: your swift/objc code can cancel a future from C++), but I have not implemented this yet.
The reason why I'm creating an incomplete PR is that I'd like early feedback (@li-feng-sc 🙏 ). Concretely:
djinni::Future, or would you prefer a separate class, for exampleCancelableFuture? Do you agree with my implementation approach so far?Examples
Cancellation forwarding:
Checking for cancellation
Notes
The implementation is based on
inplace_stop_token, which is approved for C++26. This allows cancellation with a well defined interface and minimal overhead (no extra heap allocations etc). The token is stored in a futures SharedState.The overhead could probably be further reduced by replacing the mutex with atomics, but I've decided to go for a simple implementation first