util: rename Scheduler::scheduleEvent to schedule

Deprecate Scheduler::scheduleEvent and Scheduler::cancelEvent

refs #4883

Change-Id: I2bb16922aff04300d92dfd276dd436958a96929a
diff --git a/examples/consumer-with-timer.cpp b/examples/consumer-with-timer.cpp
index b095d4c..04c6037 100644
--- a/examples/consumer-with-timer.cpp
+++ b/examples/consumer-with-timer.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2019 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -56,7 +56,7 @@
     std::cout << "Sending " << interest << std::endl;
 
     // Schedule a new event
-    m_scheduler.scheduleEvent(3_s, [this] { delayedInterest(); });
+    m_scheduler.schedule(3_s, [this] { delayedInterest(); });
 
     // m_ioService.run() will block until all events finished or m_ioService.stop() is called
     m_ioService.run();
diff --git a/ndn-cxx/face.cpp b/ndn-cxx/face.cpp
index a134e8e..a225a9d 100644
--- a/ndn-cxx/face.cpp
+++ b/ndn-cxx/face.cpp
@@ -318,7 +318,7 @@
     }
 
     if (timeout > time::milliseconds::zero()) {
-      m_impl->m_processEventsTimeoutEvent = m_impl->m_scheduler.scheduleEvent(timeout,
+      m_impl->m_processEventsTimeoutEvent = m_impl->m_scheduler.schedule(timeout,
         [&io = m_ioService, &work = m_impl->m_ioServiceWork] {
           io.stop();
           work.reset();
diff --git a/ndn-cxx/impl/pending-interest.hpp b/ndn-cxx/impl/pending-interest.hpp
index a139fc2..a41934e 100644
--- a/ndn-cxx/impl/pending-interest.hpp
+++ b/ndn-cxx/impl/pending-interest.hpp
@@ -185,8 +185,8 @@
   void
   scheduleTimeoutEvent(Scheduler& scheduler)
   {
-    m_timeoutEvent = scheduler.scheduleEvent(m_interest->getInterestLifetime(),
-                                             [=] { this->invokeTimeoutCallback(); });
+    m_timeoutEvent = scheduler.schedule(m_interest->getInterestLifetime(),
+                                        [=] { this->invokeTimeoutCallback(); });
   }
 
   /**
diff --git a/ndn-cxx/ims/in-memory-storage-entry.cpp b/ndn-cxx/ims/in-memory-storage-entry.cpp
index 7b04271..5720bc9 100644
--- a/ndn-cxx/ims/in-memory-storage-entry.cpp
+++ b/ndn-cxx/ims/in-memory-storage-entry.cpp
@@ -45,7 +45,7 @@
 void
 InMemoryStorageEntry::scheduleMarkStale(Scheduler& sched, time::nanoseconds after)
 {
-  m_markStaleEventId = sched.scheduleEvent(after, [this] { m_isFresh = false; });
+  m_markStaleEventId = sched.schedule(after, [this] { m_isFresh = false; });
 }
 
 } // namespace ndn
diff --git a/ndn-cxx/net/dns.cpp b/ndn-cxx/net/dns.cpp
index 55f0822..9942867 100644
--- a/ndn-cxx/net/dns.cpp
+++ b/ndn-cxx/net/dns.cpp
@@ -57,7 +57,7 @@
 
     m_resolver.async_resolve(q, bind(&Resolver::onResolveResult, this, _1, _2, self));
 
-    m_resolveTimeout = m_scheduler.scheduleEvent(timeout, [=] { onResolveTimeout(self); });
+    m_resolveTimeout = m_scheduler.schedule(timeout, [=] { onResolveTimeout(self); });
   }
 
   iterator
@@ -71,7 +71,7 @@
   onResolveResult(const boost::system::error_code& error,
                   iterator it, const shared_ptr<Resolver>& self)
   {
-    m_scheduler.cancelEvent(m_resolveTimeout);
+    m_resolveTimeout.cancel();
     // ensure the Resolver isn't destructed while callbacks are still pending, see #2653
     m_resolver.get_io_service().post([self] {});
 
diff --git a/ndn-cxx/net/impl/network-monitor-impl-osx.cpp b/ndn-cxx/net/impl/network-monitor-impl-osx.cpp
index f0866b8..b10c6eb 100644
--- a/ndn-cxx/net/impl/network-monitor-impl-osx.cpp
+++ b/ndn-cxx/net/impl/network-monitor-impl-osx.cpp
@@ -184,7 +184,7 @@
 NetworkMonitorImplOsx::scheduleCfLoop()
 {
   // poll each second for new events
-  m_cfLoopEvent = m_scheduler.scheduleEvent(1_s, [this] {
+  m_cfLoopEvent = m_scheduler.schedule(1_s, [this] {
     // this should dispatch ready events and exit
     CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);
     scheduleCfLoop();
diff --git a/ndn-cxx/security/v2/certificate-fetcher-from-network.cpp b/ndn-cxx/security/v2/certificate-fetcher-from-network.cpp
index 1aef91a..df816b1 100644
--- a/ndn-cxx/security/v2/certificate-fetcher-from-network.cpp
+++ b/ndn-cxx/security/v2/certificate-fetcher-from-network.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2019 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -85,8 +85,8 @@
 
   --certRequest->nRetriesLeft;
   if (certRequest->nRetriesLeft >= 0) {
-    m_scheduler.scheduleEvent(certRequest->waitAfterNack,
-                              [=] { fetch(certRequest, state, continueValidation); });
+    m_scheduler.schedule(certRequest->waitAfterNack,
+                         [=] { fetch(certRequest, state, continueValidation); });
     certRequest->waitAfterNack *= 2;
   }
   else {
diff --git a/ndn-cxx/util/notification-subscriber.cpp b/ndn-cxx/util/notification-subscriber.cpp
index 0794e39..ce9b395 100644
--- a/ndn-cxx/util/notification-subscriber.cpp
+++ b/ndn-cxx/util/notification-subscriber.cpp
@@ -151,7 +151,7 @@
   onNack(nack);
 
   time::milliseconds delay = exponentialBackoff(nack);
-  m_nackEvent = m_scheduler.scheduleEvent(delay, [this] { sendInitialInterest(); });
+  m_nackEvent = m_scheduler.schedule(delay, [this] { sendInitialInterest(); });
 }
 
 void
diff --git a/ndn-cxx/util/scheduler.cpp b/ndn-cxx/util/scheduler.cpp
index f4b3a10..f059a4b 100644
--- a/ndn-cxx/util/scheduler.cpp
+++ b/ndn-cxx/util/scheduler.cpp
@@ -98,7 +98,7 @@
 Scheduler::~Scheduler() = default;
 
 EventId
-Scheduler::scheduleEvent(time::nanoseconds after, EventCallback callback)
+Scheduler::schedule(time::nanoseconds after, EventCallback callback)
 {
   BOOST_ASSERT(callback != nullptr);
 
diff --git a/ndn-cxx/util/scheduler.hpp b/ndn-cxx/util/scheduler.hpp
index f1a38f7..8e2e7fb 100644
--- a/ndn-cxx/util/scheduler.hpp
+++ b/ndn-cxx/util/scheduler.hpp
@@ -48,7 +48,7 @@
 /** \brief A handle of scheduled event.
  *
  *  \code
- *  EventId eid = scheduler.scheduleEvent(10_ms, [] { doSomething(); });
+ *  EventId eid = scheduler.schedule(10_ms, [] { doSomething(); });
  *  eid.cancel(); // cancel the event
  *  \endcode
  *
@@ -116,7 +116,7 @@
  *
  *  \code
  *  {
- *    ScopedEventId eid = scheduler.scheduleEvent(10_ms, [] { doSomething(); });
+ *    ScopedEventId eid = scheduler.schedule(10_ms, [] { doSomething(); });
  *  } // eid goes out of scope, canceling the event
  *  \endcode
  *
@@ -154,12 +154,20 @@
    *  \return EventId that can be used to cancel the scheduled event
    */
   EventId
-  scheduleEvent(time::nanoseconds after, EventCallback callback);
+  schedule(time::nanoseconds after, EventCallback callback);
 
-  /** \brief Cancel a scheduled event
-   *
-   *  You may also invoke `eid.cancel()`
+  /** \deprecated use schedule(after, callback)
    */
+  [[deprecated("use schedule(after, callback)")]]
+  EventId
+  scheduleEvent(time::nanoseconds after, EventCallback callback)
+  {
+    return schedule(after, std::move(callback));
+  }
+
+  /** \deprecated use EventId::cancel()
+   */
+  [[deprecated("use EventId::cancel()")]]
   void
   cancelEvent(const EventId& eid)
   {
diff --git a/ndn-cxx/util/segment-fetcher.cpp b/ndn-cxx/util/segment-fetcher.cpp
index 09cfd4e..680ff59 100644
--- a/ndn-cxx/util/segment-fetcher.cpp
+++ b/ndn-cxx/util/segment-fetcher.cpp
@@ -126,34 +126,12 @@
     interest.refreshNonce();
   }
 
-  weak_ptr<SegmentFetcher> weakSelf = m_this;
-
-  m_nSegmentsInFlight++;
-  auto pendingInterest = m_face.expressInterest(interest,
-                                                bind(&SegmentFetcher::afterSegmentReceivedCb,
-                                                     this, _1, _2, weakSelf),
-                                                bind(&SegmentFetcher::afterNackReceivedCb,
-                                                     this, _1, _2, weakSelf),
-                                                nullptr);
-  auto timeoutEvent =
-    m_scheduler.scheduleEvent(m_options.useConstantInterestTimeout ? m_options.maxTimeout : getEstimatedRto(),
-                              bind(&SegmentFetcher::afterTimeoutCb, this, interest, weakSelf));
-
-  if (isRetransmission) {
-    updateRetransmittedSegment(0, pendingInterest, timeoutEvent);
-  }
-  else {
-    BOOST_ASSERT(m_pendingSegments.count(0) == 0);
-    m_pendingSegments.emplace(0, PendingSegment{SegmentState::FirstInterest, time::steady_clock::now(),
-                                                pendingInterest, timeoutEvent});
-  }
+  sendInterest(0, interest, isRetransmission);
 }
 
 void
 SegmentFetcher::fetchSegmentsInWindow(const Interest& origInterest)
 {
-  weak_ptr<SegmentFetcher> weakSelf = m_this;
-
   if (checkAllSegmentsReceived()) {
     // All segments have been retrieved
     return finalizeFetch();
@@ -194,32 +172,43 @@
     interest.setMustBeFresh(false);
     interest.setInterestLifetime(m_options.interestLifetime);
     interest.refreshNonce();
-
-    m_nSegmentsInFlight++;
-    auto pendingInterest = m_face.expressInterest(interest,
-                                                  bind(&SegmentFetcher::afterSegmentReceivedCb,
-                                                       this, _1, _2, weakSelf),
-                                                  bind(&SegmentFetcher::afterNackReceivedCb,
-                                                       this, _1, _2, weakSelf),
-                                                  nullptr);
-    auto timeoutEvent =
-      m_scheduler.scheduleEvent(m_options.useConstantInterestTimeout ? m_options.maxTimeout : getEstimatedRto(),
-                                bind(&SegmentFetcher::afterTimeoutCb, this, interest, weakSelf));
-
-    if (segment.second) { // Retransmission
-      updateRetransmittedSegment(segment.first, pendingInterest, timeoutEvent);
-    }
-    else { // First request for segment
-      BOOST_ASSERT(m_pendingSegments.count(segment.first) == 0);
-      m_pendingSegments.emplace(segment.first, PendingSegment{SegmentState::FirstInterest,
-                                                              time::steady_clock::now(),
-                                                              pendingInterest, timeoutEvent});
-      m_highInterest = segment.first;
-    }
+    sendInterest(segment.first, interest, segment.second);
   }
 }
 
 void
+SegmentFetcher::sendInterest(uint64_t segNum, const Interest& interest, bool isRetransmission)
+{
+  weak_ptr<SegmentFetcher> weakSelf = m_this;
+
+  ++m_nSegmentsInFlight;
+  auto pendingInterest = m_face.expressInterest(interest,
+    [this, weakSelf] (const Interest& interest, const Data& data) {
+      afterSegmentReceivedCb(interest, data, weakSelf);
+    },
+    [this, weakSelf] (const Interest& interest, const lp::Nack& nack) {
+      afterNackReceivedCb(interest, nack, weakSelf);
+    },
+    nullptr);
+
+  auto timeout = m_options.useConstantInterestTimeout ? m_options.maxTimeout : getEstimatedRto();
+  auto timeoutEvent = m_scheduler.schedule(timeout, [this, interest, weakSelf] {
+    afterTimeoutCb(interest, weakSelf);
+  });
+
+  if (isRetransmission) {
+    updateRetransmittedSegment(segNum, pendingInterest, timeoutEvent);
+    return;
+  }
+
+  PendingSegment pendingSegment{SegmentState::FirstInterest, time::steady_clock::now(),
+                                pendingInterest, timeoutEvent};
+  bool isNew = m_pendingSegments.emplace(segNum, std::move(pendingSegment)).second;
+  BOOST_VERIFY(isNew);
+  m_highInterest = segNum;
+}
+
+void
 SegmentFetcher::afterSegmentReceivedCb(const Interest& origInterest, const Data& data,
                                        const weak_ptr<SegmentFetcher>& weakSelf)
 {
diff --git a/ndn-cxx/util/segment-fetcher.hpp b/ndn-cxx/util/segment-fetcher.hpp
index 9b7f5bb..4e556d4 100644
--- a/ndn-cxx/util/segment-fetcher.hpp
+++ b/ndn-cxx/util/segment-fetcher.hpp
@@ -189,6 +189,9 @@
   fetchSegmentsInWindow(const Interest& origInterest);
 
   void
+  sendInterest(uint64_t segNum, const Interest& interest, bool isRetransmission);
+
+  void
   afterSegmentReceivedCb(const Interest& origInterest, const Data& data,
                          const weak_ptr<SegmentFetcher>& weakSelf);
 
diff --git a/tests/integrated/face.cpp b/tests/integrated/face.cpp
index 5798b0f..ddc0cd3 100644
--- a/tests/integrated/face.cpp
+++ b/tests/integrated/face.cpp
@@ -87,7 +87,7 @@
     }
 
     outcome = '?';
-    return sched.scheduleEvent(delay, [this, interest, &outcome] {
+    return sched.schedule(delay, [this, interest, &outcome] {
       face2->expressInterest(interest,
         [&] (const Interest&, const Data&) { outcome = 'D'; },
         [&] (const Interest&, const lp::Nack&) { outcome = 'N'; },
@@ -108,7 +108,7 @@
   scheduler::EventId
   terminateAfter(time::nanoseconds delay)
   {
-    return sched.scheduleEvent(delay, [this] { face.getIoService().stop(); });
+    return sched.schedule(delay, [this] { face.getIoService().stop(); });
   }
 
 protected:
@@ -184,19 +184,19 @@
     [&] (const Name&) { ++nRegSuccess; },
     [] (const Name&, const std::string& msg) { BOOST_ERROR("unexpected register prefix failure: " << msg); });
 
-  this->sched.scheduleEvent(1_s, [&nRegSuccess] {
+  this->sched.schedule(1_s, [&nRegSuccess] {
     BOOST_CHECK_EQUAL(nRegSuccess, 1);
     std::string output = executeCommand("nfdc route list | grep /Hello/World");
     BOOST_CHECK(!output.empty());
   });
 
-  this->sched.scheduleEvent(2_s, [this, id, &nUnregSuccess] {
+  this->sched.schedule(2_s, [this, id, &nUnregSuccess] {
     this->face.unregisterPrefix(id,
       [&] { ++nUnregSuccess; },
       [] (const std::string& msg) { BOOST_ERROR("unexpected unregister prefix failure: " << msg); });
   });
 
-  this->sched.scheduleEvent(3_s, [&nUnregSuccess] {
+  this->sched.schedule(3_s, [&nUnregSuccess] {
     BOOST_CHECK_EQUAL(nUnregSuccess, 1);
 
     // Boost.Test would fail if a child process exits with non-zero. http://stackoverflow.com/q/5325202
@@ -221,7 +221,7 @@
     [&] (const Name&) { ++nRegSuccess2; },
     [] (const Name&, const std::string& msg) { BOOST_ERROR("unexpected register prefix failure: " << msg); });
 
-  this->sched.scheduleEvent(500_ms, [] {
+  this->sched.schedule(500_ms, [] {
     std::string output = executeCommand("nfdc route list | grep /Hello/World");
     BOOST_CHECK(!output.empty());
   });
@@ -247,7 +247,7 @@
     [&] (const Name&) { ++nRegSuccess; },
     [] (const Name&, const std::string& msg) { BOOST_ERROR("unexpected register prefix failure: " << msg); });
 
-  this->sched.scheduleEvent(700_ms, [] {
+  this->sched.schedule(700_ms, [] {
     std::string output = executeCommand("nfdc route list | grep /Hello/World");
     BOOST_CHECK(!output.empty());
   });
@@ -272,7 +272,7 @@
   this->face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
     [&] (const InterestFilter&, const Interest& interest) { BOOST_ERROR("unexpected Interest"); });
 
-  this->sched.scheduleEvent(700_ms, [] {
+  this->sched.schedule(700_ms, [] {
     // Boost.Test would fail if a child process exits with non-zero. http://stackoverflow.com/q/5325202
     std::string output = executeCommand("nfdc route list | grep /Hello/World || true");
     BOOST_CHECK(output.empty());
diff --git a/tests/integrated/scheduler-benchmark.cpp b/tests/integrated/scheduler-benchmark.cpp
index 9bc4600..ecf6342 100644
--- a/tests/integrated/scheduler-benchmark.cpp
+++ b/tests/integrated/scheduler-benchmark.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2019 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -45,13 +45,13 @@
 
   auto d1 = timedExecute([&] {
     for (size_t i = 0; i < nEvents; ++i) {
-      eventIds[i] = sched.scheduleEvent(1_s, []{});
+      eventIds[i] = sched.schedule(1_s, []{});
     }
   });
 
   auto d2 = timedExecute([&] {
     for (size_t i = 0; i < nEvents; ++i) {
-      sched.cancelEvent(eventIds[i]);
+      eventIds[i].cancel();
     }
   });
 
@@ -72,13 +72,13 @@
   time::steady_clock::TimePoint t2;
   // +1ms ensures this extra event is executed last. In case the overhead is less than 1ms,
   // it will be reported as 1ms.
-  sched.scheduleEvent(t1 - time::steady_clock::now() + 1_ms, [&] {
+  sched.schedule(t1 - time::steady_clock::now() + 1_ms, [&] {
     t2 = time::steady_clock::now();
     BOOST_REQUIRE_EQUAL(nExpired, nEvents);
   });
 
   for (size_t i = 0; i < nEvents; ++i) {
-    sched.scheduleEvent(t1 - time::steady_clock::now(), [&] { ++nExpired; });
+    sched.schedule(t1 - time::steady_clock::now(), [&] { ++nExpired; });
   }
 
   io.run();
diff --git a/tests/unit/security/signature-sha256-with-ecdsa.t.cpp b/tests/unit/security/signature-sha256-with-ecdsa.t.cpp
index abf15a2..3881756 100644
--- a/tests/unit/security/signature-sha256-with-ecdsa.t.cpp
+++ b/tests/unit/security/signature-sha256-with-ecdsa.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2019 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -128,15 +128,9 @@
   auto interest = makeInterest("/SecurityTestSignatureSha256WithEcdsa/InterestSignature/Interest1");
   auto interest11 = makeInterest("/SecurityTestSignatureSha256WithEcdsa/InterestSignature/Interest1");
 
-  scheduler.scheduleEvent(100_ms, [&] {
-      m_keyChain.sign(*interest, security::SigningInfo(identity));
-    });
-
+  scheduler.schedule(100_ms, [&] { m_keyChain.sign(*interest, security::SigningInfo(identity)); });
   advanceClocks(100_ms);
-  scheduler.scheduleEvent(100_ms, [&] {
-      m_keyChain.sign(*interest11, security::SigningInfo(identity));
-    });
-
+  scheduler.schedule(100_ms, [&] { m_keyChain.sign(*interest11, security::SigningInfo(identity)); });
   advanceClocks(100_ms);
 
   Block interestBlock(interest->wireEncode().wire(), interest->wireEncode().size());
diff --git a/tests/unit/security/signature-sha256-with-rsa.t.cpp b/tests/unit/security/signature-sha256-with-rsa.t.cpp
index 3fca552..2363551 100644
--- a/tests/unit/security/signature-sha256-with-rsa.t.cpp
+++ b/tests/unit/security/signature-sha256-with-rsa.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2019 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -133,15 +133,9 @@
   auto interest = makeInterest("/SecurityTestSignatureSha256WithRsa/InterestSignature/Interest1");
   auto interest11 = makeInterest("/SecurityTestSignatureSha256WithRsa/InterestSignature/Interest1");
 
-  scheduler.scheduleEvent(100_ms, [&] {
-      m_keyChain.sign(*interest, security::SigningInfo(identity));
-    });
-
+  scheduler.schedule(100_ms, [&] { m_keyChain.sign(*interest, security::SigningInfo(identity)); });
   advanceClocks(100_ms);
-  scheduler.scheduleEvent(100_ms, [&] {
-      m_keyChain.sign(*interest11, security::SigningInfo(identity));
-    });
-
+  scheduler.schedule(100_ms, [&] { m_keyChain.sign(*interest11, security::SigningInfo(identity)); });
   advanceClocks(100_ms);
 
   Block interestBlock(interest->wireEncode().wire(), interest->wireEncode().size());
diff --git a/tests/unit/util/scheduler.t.cpp b/tests/unit/util/scheduler.t.cpp
index 77b60a5..6497136 100644
--- a/tests/unit/util/scheduler.t.cpp
+++ b/tests/unit/util/scheduler.t.cpp
@@ -53,25 +53,21 @@
   size_t count1 = 0;
   size_t count2 = 0;
 
-  scheduler.scheduleEvent(500_ms, [&] {
-      ++count1;
-      BOOST_CHECK_EQUAL(count2, 1);
-    });
+  scheduler.schedule(500_ms, [&] {
+    ++count1;
+    BOOST_CHECK_EQUAL(count2, 1);
+  });
 
-  EventId i = scheduler.scheduleEvent(1_s, [&] {
-      BOOST_ERROR("This event should not have been fired");
-    });
-  scheduler.cancelEvent(i);
+  EventId i = scheduler.schedule(1_s, [] { BOOST_ERROR("This event should not have been fired"); });
+  i.cancel();
 
-  scheduler.scheduleEvent(250_ms, [&] {
-      BOOST_CHECK_EQUAL(count1, 0);
-      ++count2;
-    });
+  scheduler.schedule(250_ms, [&] {
+    BOOST_CHECK_EQUAL(count1, 0);
+    ++count2;
+  });
 
-  i = scheduler.scheduleEvent(50_ms, [&] {
-      BOOST_ERROR("This event should not have been fired");
-    });
-  scheduler.cancelEvent(i);
+  i = scheduler.schedule(50_ms, [&] { BOOST_ERROR("This event should not have been fired"); });
+  i.cancel();
 
   advanceClocks(25_ms, 1000_ms);
   BOOST_CHECK_EQUAL(count1, 1);
@@ -83,7 +79,7 @@
   class MyException : public std::exception
   {
   };
-  scheduler.scheduleEvent(10_ms, [] {
+  scheduler.schedule(10_ms, [] {
     // use plain 'throw' to ensure that Scheduler does not depend on the
     // internal machinery of NDN_THROW and that it can catch all exceptions
     // regardless of how they are thrown by the application
@@ -91,7 +87,7 @@
   });
 
   bool isCallbackInvoked = false;
-  scheduler.scheduleEvent(20_ms, [&isCallbackInvoked] { isCallbackInvoked = true; });
+  scheduler.schedule(20_ms, [&isCallbackInvoked] { isCallbackInvoked = true; });
 
   BOOST_CHECK_THROW(this->advanceClocks(6_ms, 2), MyException);
   this->advanceClocks(6_ms, 2);
@@ -101,7 +97,7 @@
 BOOST_AUTO_TEST_CASE(CancelEmptyEvent)
 {
   EventId i;
-  scheduler.cancelEvent(i);
+  i.cancel();
 
   // avoid "test case [...] did not check any assertions" message from Boost.Test
   BOOST_CHECK(true);
@@ -110,43 +106,33 @@
 BOOST_AUTO_TEST_CASE(SelfCancel)
 {
   EventId selfEventId;
-  selfEventId = scheduler.scheduleEvent(100_ms, [&] {
-      scheduler.cancelEvent(selfEventId);
-    });
-
+  selfEventId = scheduler.schedule(100_ms, [&] { selfEventId.cancel(); });
   BOOST_REQUIRE_NO_THROW(advanceClocks(100_ms, 10));
 }
 
 class SelfRescheduleFixture : public SchedulerFixture
 {
 public:
-  SelfRescheduleFixture()
-    : count(0)
-  {
-  }
-
   void
   reschedule()
   {
-    EventId eventId = scheduler.scheduleEvent(100_ms,
-                                              bind(&SelfRescheduleFixture::reschedule, this));
-    scheduler.cancelEvent(selfEventId);
+    EventId eventId = scheduler.schedule(100_ms, bind(&SelfRescheduleFixture::reschedule, this));
+    selfEventId.cancel();
     selfEventId = eventId;
 
     if (count < 5)
       count++;
     else
-      scheduler.cancelEvent(selfEventId);
+      selfEventId.cancel();
   }
 
   void
   reschedule2()
   {
-    scheduler.cancelEvent(selfEventId);
+    selfEventId.cancel();
 
     if (count < 5)  {
-      selfEventId = scheduler.scheduleEvent(100_ms,
-                                            bind(&SelfRescheduleFixture::reschedule2, this));
+      selfEventId = scheduler.schedule(100_ms, bind(&SelfRescheduleFixture::reschedule2, this));
       count++;
     }
   }
@@ -154,90 +140,70 @@
   void
   reschedule3()
   {
-    scheduler.cancelEvent(selfEventId);
+    selfEventId.cancel();
 
-    scheduler.scheduleEvent(100_ms, [&] { ++count; });
-    scheduler.scheduleEvent(100_ms, [&] { ++count; });
-    scheduler.scheduleEvent(100_ms, [&] { ++count; });
-    scheduler.scheduleEvent(100_ms, [&] { ++count; });
-    scheduler.scheduleEvent(100_ms, [&] { ++count; });
-    scheduler.scheduleEvent(100_ms, [&] { ++count; });
+    scheduler.schedule(100_ms, [&] { ++count; });
+    scheduler.schedule(100_ms, [&] { ++count; });
+    scheduler.schedule(100_ms, [&] { ++count; });
+    scheduler.schedule(100_ms, [&] { ++count; });
+    scheduler.schedule(100_ms, [&] { ++count; });
+    scheduler.schedule(100_ms, [&] { ++count; });
   }
 
 public:
   EventId selfEventId;
-  size_t count;
+  size_t count = 0;
 };
 
 BOOST_FIXTURE_TEST_CASE(Reschedule, SelfRescheduleFixture)
 {
-  selfEventId = scheduler.scheduleEvent(0_s,
-                                        bind(&SelfRescheduleFixture::reschedule, this));
-
+  selfEventId = scheduler.schedule(0_s, bind(&SelfRescheduleFixture::reschedule, this));
   BOOST_REQUIRE_NO_THROW(advanceClocks(50_ms, 1000_ms));
-
   BOOST_CHECK_EQUAL(count, 5);
 }
 
 BOOST_FIXTURE_TEST_CASE(Reschedule2, SelfRescheduleFixture)
 {
-  selfEventId = scheduler.scheduleEvent(0_s,
-                                        bind(&SelfRescheduleFixture::reschedule2, this));
-
+  selfEventId = scheduler.schedule(0_s, bind(&SelfRescheduleFixture::reschedule2, this));
   BOOST_REQUIRE_NO_THROW(advanceClocks(50_ms, 1000_ms));
-
   BOOST_CHECK_EQUAL(count, 5);
 }
 
 BOOST_FIXTURE_TEST_CASE(Reschedule3, SelfRescheduleFixture)
 {
-  selfEventId = scheduler.scheduleEvent(0_s,
-                                        bind(&SelfRescheduleFixture::reschedule3, this));
-
+  selfEventId = scheduler.schedule(0_s, bind(&SelfRescheduleFixture::reschedule3, this));
   BOOST_REQUIRE_NO_THROW(advanceClocks(50_ms, 1000_ms));
-
   BOOST_CHECK_EQUAL(count, 6);
 }
 
 class CancelAllFixture : public SchedulerFixture
 {
 public:
-  CancelAllFixture()
-    : count(0)
-  {
-  }
-
   void
   event()
   {
     ++count;
-
-    scheduler.scheduleEvent(1_s, [&] { event(); });
+    scheduler.schedule(1_s, [&] { event(); });
   }
 
 public:
-  uint32_t count;
+  uint32_t count = 0;
 };
 
 BOOST_FIXTURE_TEST_CASE(CancelAll, CancelAllFixture)
 {
-  scheduler.scheduleEvent(500_ms, [&] { scheduler.cancelAllEvents(); });
-
-  scheduler.scheduleEvent(1_s, [&] { event(); });
-
-  scheduler.scheduleEvent(3_s, [] {
-      BOOST_ERROR("This event should have been cancelled" );
-    });
+  scheduler.schedule(500_ms, [&] { scheduler.cancelAllEvents(); });
+  scheduler.schedule(1_s, [&] { event(); });
+  scheduler.schedule(3_s, [] { BOOST_ERROR("This event should have been cancelled" ); });
 
   advanceClocks(100_ms, 100);
-
   BOOST_CHECK_EQUAL(count, 0);
 }
 
 BOOST_AUTO_TEST_CASE(CancelAllWithScopedEventId) // Bug 3691
 {
   Scheduler sched(io);
-  ScopedEventId eid = sched.scheduleEvent(10_ms, []{});
+  ScopedEventId eid = sched.schedule(10_ms, []{});
   sched.cancelAllEvents();
   eid.cancel(); // should not crash
 
@@ -263,7 +229,7 @@
   BOOST_CHECK_EQUAL(eid == eid2, true);
   BOOST_CHECK_EQUAL(eid != eid2, false);
 
-  eid = scheduler.scheduleEvent(10_ms, []{});
+  eid = scheduler.schedule(10_ms, []{});
   BOOST_CHECK_EQUAL(eid == eid2, false);
   BOOST_CHECK_EQUAL(eid != eid2, true);
 
@@ -271,7 +237,7 @@
   BOOST_CHECK_EQUAL(eid, eid2);
   BOOST_CHECK_EQUAL(eid != eid2, false);
 
-  eid2 = scheduler.scheduleEvent(10_ms, []{});
+  eid2 = scheduler.schedule(10_ms, []{});
   BOOST_CHECK_EQUAL(eid == eid2, false);
   BOOST_CHECK_NE(eid, eid2);
 }
@@ -282,12 +248,12 @@
   BOOST_CHECK_EQUAL(static_cast<bool>(eid), false);
   BOOST_CHECK_EQUAL(!eid, true);
 
-  eid = scheduler.scheduleEvent(10_ms, []{});
+  eid = scheduler.schedule(10_ms, []{});
   BOOST_CHECK_EQUAL(static_cast<bool>(eid), true);
   BOOST_CHECK_EQUAL(!eid, false);
 
   EventId eid2 = eid;
-  scheduler.cancelEvent(eid2);
+  eid2.cancel();
   BOOST_CHECK(!eid);
   BOOST_CHECK(!eid2);
 }
@@ -295,17 +261,17 @@
 BOOST_AUTO_TEST_CASE(DuringCallback)
 {
   EventId eid;
-  EventId eid2 = scheduler.scheduleEvent(20_ms, []{});
+  EventId eid2 = scheduler.schedule(20_ms, []{});
 
   bool isCallbackInvoked = false;
-  eid = scheduler.scheduleEvent(10_ms, [this, &eid, &eid2, &isCallbackInvoked] {
+  eid = scheduler.schedule(10_ms, [&eid, &eid2, &isCallbackInvoked] {
     isCallbackInvoked = true;
 
     // eid is "expired" during callback execution
     BOOST_CHECK(!eid);
     BOOST_CHECK_NE(eid, eid2);
 
-    scheduler.cancelEvent(eid2);
+    eid2.cancel();
     BOOST_CHECK_EQUAL(eid, eid2);
   });
 
@@ -316,7 +282,7 @@
 BOOST_AUTO_TEST_CASE(Reset)
 {
   bool isCallbackInvoked = false;
-  EventId eid = scheduler.scheduleEvent(10_ms, [&isCallbackInvoked] { isCallbackInvoked = true; });
+  EventId eid = scheduler.schedule(10_ms, [&isCallbackInvoked] { isCallbackInvoked = true; });
   eid.reset();
   BOOST_CHECK(!eid);
 
@@ -331,7 +297,7 @@
   EventId eid;
   BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(eid), nullString);
 
-  eid = scheduler.scheduleEvent(10_ms, []{});
+  eid = scheduler.schedule(10_ms, []{});
   BOOST_TEST_MESSAGE("eid=" << eid);
   BOOST_CHECK_NE(boost::lexical_cast<std::string>(eid), nullString);
 }
@@ -346,7 +312,7 @@
 {
   int hit = 0;
   {
-    ScopedEventId se = scheduler.scheduleEvent(10_ms, [&] { ++hit; });
+    ScopedEventId se = scheduler.schedule(10_ms, [&] { ++hit; });
   } // se goes out of scope
   this->advanceClocks(1_ms, 15);
   BOOST_CHECK_EQUAL(hit, 0);
@@ -355,8 +321,8 @@
 BOOST_AUTO_TEST_CASE(Assign)
 {
   int hit1 = 0, hit2 = 0;
-  ScopedEventId se1 = scheduler.scheduleEvent(10_ms, [&] { ++hit1; });
-  se1 = scheduler.scheduleEvent(10_ms, [&] { ++hit2; });
+  ScopedEventId se1 = scheduler.schedule(10_ms, [&] { ++hit1; });
+  se1 = scheduler.schedule(10_ms, [&] { ++hit2; });
   this->advanceClocks(1_ms, 15);
   BOOST_CHECK_EQUAL(hit1, 0);
   BOOST_CHECK_EQUAL(hit2, 1);
@@ -366,7 +332,7 @@
 {
   int hit = 0;
   {
-    ScopedEventId se = scheduler.scheduleEvent(10_ms, [&] { ++hit; });
+    ScopedEventId se = scheduler.schedule(10_ms, [&] { ++hit; });
     se.release();
   } // se goes out of scope
   this->advanceClocks(1_ms, 15);
@@ -378,7 +344,7 @@
   int hit = 0;
   unique_ptr<ScopedEventId> se2;
   {
-    ScopedEventId se = scheduler.scheduleEvent(10_ms, [&] { ++hit; });
+    ScopedEventId se = scheduler.schedule(10_ms, [&] { ++hit; });
     se2 = make_unique<ScopedEventId>(std::move(se)); // move constructor
   } // se goes out of scope
   this->advanceClocks(1_ms, 15);
@@ -386,7 +352,7 @@
 
   ScopedEventId se3;
   {
-    ScopedEventId se = scheduler.scheduleEvent(10_ms, [&] { ++hit; });
+    ScopedEventId se = scheduler.schedule(10_ms, [&] { ++hit; });
     se3 = std::move(se); // move assignment
   } // se goes out of scope
   this->advanceClocks(1_ms, 15);
diff --git a/tests/unit/util/time-unit-test-clock.t.cpp b/tests/unit/util/time-unit-test-clock.t.cpp
index c47bdda..b65c9f9 100644
--- a/tests/unit/util/time-unit-test-clock.t.cpp
+++ b/tests/unit/util/time-unit-test-clock.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2019 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -120,7 +120,7 @@
   ndn::Scheduler scheduler(io);
 
   bool hasFired = false;
-  scheduler.scheduleEvent(100_s, [&] { hasFired = true; });
+  scheduler.schedule(100_s, [&] { hasFired = true; });
 
   io.poll();
   BOOST_CHECK_EQUAL(hasFired, false);