1e254a845SShuo Chen// copied from muduo/net/tests/TimerQueue_unittest.cc 2e254a845SShuo Chen 3e254a845SShuo Chen#include "EventLoop.h" 4e254a845SShuo Chen 5e254a845SShuo Chen#include <boost/bind.hpp> 6e254a845SShuo Chen 7e254a845SShuo Chen#include <stdio.h> 8e254a845SShuo Chen 9e254a845SShuo Chenint cnt = 0; 10e254a845SShuo Chenmuduo::EventLoop* g_loop; 11e254a845SShuo Chen 12e254a845SShuo Chenvoid printTid() 13e254a845SShuo Chen{ 14e254a845SShuo Chen printf("pid = %d, tid = %d\n", getpid(), muduo::CurrentThread::tid()); 15e254a845SShuo Chen printf("now %s\n", muduo::Timestamp::now().toString().c_str()); 16e254a845SShuo Chen} 17e254a845SShuo Chen 18e254a845SShuo Chenvoid print(const char* msg) 19e254a845SShuo Chen{ 20e254a845SShuo Chen printf("msg %s %s\n", muduo::Timestamp::now().toString().c_str(), msg); 21e254a845SShuo Chen if (++cnt == 20) 22e254a845SShuo Chen { 23e254a845SShuo Chen g_loop->quit(); 24e254a845SShuo Chen } 25e254a845SShuo Chen} 26e254a845SShuo Chen 27e254a845SShuo Chenint main() 28e254a845SShuo Chen{ 29e254a845SShuo Chen printTid(); 30e254a845SShuo Chen muduo::EventLoop loop; 31e254a845SShuo Chen g_loop = &loop; 32e254a845SShuo Chen 33e254a845SShuo Chen print("main"); 34e254a845SShuo Chen loop.runAfter(1, boost::bind(print, "once1")); 35e254a845SShuo Chen loop.runAfter(1.5, boost::bind(print, "once1.5")); 36e254a845SShuo Chen loop.runAfter(2.5, boost::bind(print, "once2.5")); 37e254a845SShuo Chen loop.runAfter(3.5, boost::bind(print, "once3.5")); 38e254a845SShuo Chen loop.runEvery(2, boost::bind(print, "every2")); 39e254a845SShuo Chen loop.runEvery(3, boost::bind(print, "every3")); 40e254a845SShuo Chen 41e254a845SShuo Chen loop.loop(); 42e254a845SShuo Chen print("main loop exits"); 43e254a845SShuo Chen sleep(1); 44e254a845SShuo Chen} 45