CancellationToken::merge()
Summary:
Combining CancellationTokens is a common pattern in user code, which requires the user to manage a CancellationSource and attach a callback per token to be merged:
```
folly::CancellationSource source;
folly::CancellationCallbacki cb1{
std::move(token1), [&] { source.requestCancellation(); }};
folly::CancellationCallback cb2{
std::move(token2), [&] { source.requestCancellation(); }};
...
co_await co_withCancellation(source.getToken(), ...);
```
This diff adds the functionality to folly:
```
co_await co_withCancellation(folly::CancellationToken::merge(token1, token2, ...), ...);
```
This diff subclasses CancellationState for simplicity. If the extra vtable ptr is a concern, we can instead template CancellationState to combine them, but that would come with a compilation speed penalty.
Reviewed By: yfeldblum
Differential Revision: D26277772
fbshipit-source-id: 169f65b4cf8f7f10f2800fb7797bb09379ecc239
Showing
Please register or sign in to comment