Split function scheduler out

I'd like to use it in more tests.

Change-Id: I17d591a525dd25b5f4061d92791159af9a0b08e8
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/events/function_scheduler.h b/aos/events/function_scheduler.h
new file mode 100644
index 0000000..7a846c6
--- /dev/null
+++ b/aos/events/function_scheduler.h
@@ -0,0 +1,33 @@
+#ifndef AOS_EVENTS_FUNCTION_SCHEDULER_H_
+#define AOS_EVENTS_FUNCTION_SCHEDULER_H_
+
+#include <functional>
+#include <map>
+
+#include "aos/events/event_loop.h"
+#include "aos/time/time.h"
+
+namespace aos {
+
+// Simple class to call a function at a time with a timer.
+class FunctionScheduler {
+ public:
+  FunctionScheduler(aos::EventLoop *event_loop);
+
+  // Schedules the function to be run at the provided time.
+  void ScheduleAt(std::function<void()> &&function,
+                  aos::monotonic_clock::time_point time);
+
+ private:
+  void RunFunctions(aos::monotonic_clock::time_point now);
+
+  aos::EventLoop *event_loop_;
+  aos::TimerHandler *timer_;
+
+  std::multimap<aos::monotonic_clock::time_point, std::function<void()>>
+      functions_;
+};
+
+}  // namespace aos
+
+#endif  // AOS_EVENTS_FUNCTION_SCHEDULER_H_