Adds a new timer \return Returns the ID of the new timer. You can use this ID to cancel the timer
| 98 | // Returns the ID of the new timer. You can use this ID to cancel the |
| 99 | // timer |
| 100 | uint64_t add(std::chrono::milliseconds milliseconds, std::function<void(bool)> handler) |
| 101 | { |
| 102 | WorkItem item; |
| 103 | item.end = ClockT::now() + milliseconds; |
| 104 | item.handler = std::move(handler); |
| 105 | |
| 106 | std::unique_lock<std::mutex> lk(m_mtx); |
| 107 | uint64_t id = ++m_idcounter; |
| 108 | item.id = id; |
| 109 | m_items.push(std::move(item)); |
| 110 | lk.unlock(); |
| 111 | |
| 112 | // Something changed, so wake up timer thread |
| 113 | m_checkWork.notify(); |
| 114 | return id; |
| 115 | } |
| 116 | |
| 117 | //! Cancels the specified timer |
| 118 | // \return |