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