12745a763SShuo Chen// copied from muduo/net/tests/TimerQueue_unittest.cc
22745a763SShuo Chen
32745a763SShuo Chen#include "EventLoop.h"
42745a763SShuo Chen
52745a763SShuo Chen#include <boost/bind.hpp>
62745a763SShuo Chen
72745a763SShuo Chen#include <stdio.h>
82745a763SShuo Chen
92745a763SShuo Chenint cnt = 0;
102745a763SShuo Chenmuduo::EventLoop* g_loop;
112745a763SShuo Chen
122745a763SShuo Chenvoid printTid()
132745a763SShuo Chen{
142745a763SShuo Chen  printf("pid = %d, tid = %d\n", getpid(), muduo::CurrentThread::tid());
152745a763SShuo Chen  printf("now %s\n", muduo::Timestamp::now().toString().c_str());
162745a763SShuo Chen}
172745a763SShuo Chen
182745a763SShuo Chenvoid print(const char* msg)
192745a763SShuo Chen{
202745a763SShuo Chen  printf("msg %s %s\n", muduo::Timestamp::now().toString().c_str(), msg);
212745a763SShuo Chen  if (++cnt == 20)
222745a763SShuo Chen  {
232745a763SShuo Chen    g_loop->quit();
242745a763SShuo Chen  }
252745a763SShuo Chen}
262745a763SShuo Chen
272745a763SShuo Chenint main()
282745a763SShuo Chen{
292745a763SShuo Chen  printTid();
302745a763SShuo Chen  muduo::EventLoop loop;
312745a763SShuo Chen  g_loop = &loop;
322745a763SShuo Chen
332745a763SShuo Chen  print("main");
342745a763SShuo Chen  loop.runAfter(1, boost::bind(print, "once1"));
352745a763SShuo Chen  loop.runAfter(1.5, boost::bind(print, "once1.5"));
362745a763SShuo Chen  loop.runAfter(2.5, boost::bind(print, "once2.5"));
372745a763SShuo Chen  loop.runAfter(3.5, boost::bind(print, "once3.5"));
382745a763SShuo Chen  loop.runEvery(2, boost::bind(print, "every2"));
392745a763SShuo Chen  loop.runEvery(3, boost::bind(print, "every3"));
402745a763SShuo Chen
412745a763SShuo Chen  loop.loop();
422745a763SShuo Chen  print("main loop exits");
432745a763SShuo Chen  sleep(1);
442745a763SShuo Chen}
45