|
13 | 13 | // owns the ability to trigger cancellation, lightweight tokens (derived from |
14 | 14 | // the source) can be freely passed around, and CancellationCallback provides |
15 | 15 | // RAII registration of a callback tied to a token. |
16 | | -// |
17 | | -// Significant differences from the C++20 design: |
18 | | -// |
19 | | -// 1. No stop_possible() semantics. C++20's stop_source / stop_token track |
20 | | -// whether any stop_source for the associated state is still alive; if not, |
21 | | -// stop_possible() returns false and stop_callback constructors become |
22 | | -// no-ops. CancellationSource has no such tracking: tokens and callbacks |
23 | | -// behave the same regardless of whether any source is still alive. |
24 | | -// |
25 | | -// 2. Heap-allocated callbacks. C++20's stop_callback<F> stores F inline in |
26 | | -// the callback object to avoid heap allocation. CancellationCallback |
27 | | -// stores its callable inside a Continuation<void()>, which heap-allocates |
28 | | -// via unique_ptr. This avoids a template parameter on CancellationCallback |
29 | | -// at the cost of one allocation per registration. |
30 | 16 |
|
31 | 17 | namespace launchdarkly::async { |
32 | 18 |
|
@@ -230,11 +216,6 @@ inline CancellationToken CancellationSource::GetToken() const { |
230 | 216 | // by the callback. |
231 | 217 | // - CancellationCallback is non-copyable and non-movable, matching C++20's |
232 | 218 | // stop_callback. |
233 | | -// |
234 | | -// Unlike C++20's stop_callback<F>, CancellationCallback is not a template: |
235 | | -// the callable is accepted as any type that converts to Continuation<void()>, |
236 | | -// and stored heap-allocated inside one. This avoids a template parameter at |
237 | | -// the cost of one allocation per registration. |
238 | 219 | class CancellationCallback { |
239 | 220 | public: |
240 | 221 | CancellationCallback(CancellationToken token, Continuation<void()> cb) |
|
0 commit comments