Older/ToolKit/Poller/Timer.h

40 lines
1.1 KiB
C
Raw Normal View History

2024-09-28 23:55:00 +08:00
/*
* Copyright (c) 2016 The ZLToolKit project authors. All Rights Reserved.
*
* This file is part of ZLToolKit(https://github.com/ZLMediaKit/ZLToolKit).
*
* Use of this source code is governed by MIT license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
#ifndef Timer_h
#define Timer_h
#include <functional>
#include "EventPoller.h"
namespace toolkit {
class Timer {
public:
using Ptr = std::shared_ptr<Timer>;
/**
*
* @param second
* @param cb true表示重复下次任务
* @param poller EventPoller对象nullptr
*/
Timer(float second, const std::function<bool()> &cb, const EventPoller::Ptr &poller);
~Timer();
private:
std::weak_ptr<EventPoller::DelayTask> _tag;
//定时器保持EventPoller的强引用
EventPoller::Ptr _poller;
};
} // namespace toolkit
#endif /* Timer_h */