| 1546 | |
| 1547 | template <typename T> |
| 1548 | void after( |
| 1549 | const std::shared_ptr<Latch>& latch, |
| 1550 | const std::shared_ptr<Promise<T>>& promise, |
| 1551 | const std::shared_ptr<Option<Timer>>& timer, |
| 1552 | const Future<T>& future) |
| 1553 | { |
| 1554 | CHECK(!future.isPending()); |
| 1555 | if (latch->trigger()) { |
| 1556 | // If this callback executes first (i.e., we triggered the latch) |
| 1557 | // it must be the case that `timer` is still some and we can try |
| 1558 | // and cancel the timer. |
| 1559 | CHECK_SOME(*timer); |
| 1560 | Clock::cancel(timer->get()); |
| 1561 | |
| 1562 | // We also force the timer to get deallocated so that there isn't |
| 1563 | // a cicular reference of the timer with itself which keeps around |
| 1564 | // a reference to the original future. |
| 1565 | *timer = None(); |
| 1566 | |
| 1567 | promise->associate(future); |
| 1568 | } |
| 1569 | } |
| 1570 | |
| 1571 | } // namespace internal { |
| 1572 | |