/** * * Timer.h * An Tao * * Public header file in trantor lib. * * Copyright 2018, An Tao. All rights reserved. * Use of this source code is governed by a BSD-style license * that can be found in the License file. * * */ #pragma once #include #include #include #include #include #include namespace trantor { using TimerId = uint64_t; using TimePoint = std::chrono::steady_clock::time_point; using TimeInterval = std::chrono::microseconds; class Timer : public NonCopyable { public: Timer(const TimerCallback &cb, const TimePoint &when, const TimeInterval &interval); Timer(TimerCallback &&cb, const TimePoint &when, const TimeInterval &interval); ~Timer() { // std::cout<<"Timer unconstract!"<(const Timer &t) const; const TimePoint &when() const { return when_; } bool isRepeat() { return repeat_; } TimerId id() { return id_; } private: TimerCallback callback_; TimePoint when_; const TimeInterval interval_; const bool repeat_; const TimerId id_; static std::atomic timersCreated_; }; } // namespace trantor