liuxiaolong
2021-07-20 58d904a328c0d849769b483e901a0be9426b8209
src/timed_queue.h
@@ -45,46 +45,4 @@
   Data data_;
};
template <class Data, class ClockType = std::chrono::steady_clock>
class TimedQueue
{
   typedef TimedData<Data, ClockType> Record;
public:
   typedef typename Record::Clock Clock;
   typedef typename Record::TimePoint TimePoint;
   typedef typename Record::Duration Duration;
private:
   typedef std::list<Record> Queue;
   Synced<Queue> queue_;
public:
   void Push(Data &&data, const TimePoint &expire) { queue_->emplace_back(expire, std::move(data)); }
   void Push(Data const &data, const TimePoint &expire) { queue_->emplace_back(expire, data); }
   void Push(Data &&data, Duration const &timeout) { Push(std::move(data), Clock::now() + timeout); }
   void Push(Data const &data, Duration const &timeout) { Push(data, Clock::now() + timeout); }
   template <class Func>
   void CheckAll(Func const &func)
   {
      queue_.Apply([&](Queue &q) {
         if (q.empty()) {
            return;
         }
         auto it = q.begin();
         do {
            if (it->Expired()) {
               it = q.erase(it);
            } else if (func(it->data())) {
               it = q.erase(it);
            } else {
               ++it;
            }
         } while (it != q.end());
      });
   }
};
#endif // end of include guard: TIMED_QUEUE_Y2YLRBS3