代码拉取完成,页面将自动刷新
#include "HeapTimer.h"
#include "TimeWheel.h"
int main()
{
int msgid=0;
//timewheel test example
auto wheelt=[&msgid](int id,int delay,std::string name){
std::cout<< ++msgid <<" name:"<<name<< " id:"<<id<<" delay:"<<delay<<std::endl;
};
TimeWheel* wheel_timer=new TimeWheel();
wheel_timer->addTimeWheelArray(60,1000,"sceond");
wheel_timer->addTimeWheelArray(1000,1,"milisceond");
wheel_timer->addTimeWheelArray(60,60*1000,"min");
wheel_timer->addTimer("test1",2000,wheelt,TimeWheelNode::TIMER_TYPE_CYCLE);
wheel_timer->addTimer("test2",8000,wheelt,TimeWheelNode::TIMER_TYPE_CYCLE);
wheel_timer->addTimer("test3",3000,wheelt,TimeWheelNode::TIMER_TYPE_CYCLE);
wheel_timer->start();
for (int i = 0; i < 20; i++)
{
std::cout<< ++msgid<<" " << i<<std::endl;
if(i==17)
wheel_timer->stop();
sleep(1);
}
wheel_timer->deleteTimeWheelArray(1);
wheel_timer->deleteTimeWheelArray(60*1000);
wheel_timer->deleteTimeWheelArray(1000);
// heaptimer test example
// auto test=[&msgid](int id,int timestamp){
// std::cout<< ++msgid << " id:"<<id<<" timestamp:"<<timestamp<<std::endl;
// // std::cout<< ++msgid <<std::endl;
// };
// int msgid=0;
// HeapTimer *timer=HeapTimer::instance();
// auto test=[&msgid](int id,int timestamp){
// std::cout<< ++msgid << " id:"<<id<<" timestamp:"<<timestamp<<std::endl;
// // std::cout<< ++msgid <<std::endl;
// };
// timer->addTimer(new TimeNode(5,test,TimeNode::TimerType::TIMER_TYPE_ONCE));
// timer->addTimer(new TimeNode(4,test,TimeNode::TimerType::TIMER_TYPE_ONCE));
// timer->addTimer(new TimeNode(3,test,TimeNode::TimerType::TIMER_TYPE_ONCE));
// timer->addTimer(new TimeNode(2,test,TimeNode::TimerType::TIMER_TYPE_CYCLE));
// timer->addTimer(new TimeNode(1,test,TimeNode::TimerType::TIMER_TYPE_ONCE));
// timer->start();
// for (int i = 0; i < 10; i++)
// {
// std::cout<< ++msgid <<std::endl;
// if(i==5) timer->stop();
// sleep(2);
// }
getchar();
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。