Skip to content

Instantly share code, notes, and snippets.

@christianparpart
Created January 22, 2015 11:30
Show Gist options
  • Save christianparpart/c84fcb76526a4d1d0747 to your computer and use it in GitHub Desktop.
Save christianparpart/c84fcb76526a4d1d0747 to your computer and use it in GitHub Desktop.
draft
class Executor {
public:
typedef std::function<void()> Task;
virtual void execute(Task task) = 0;
protected:
void setExceptionHandler(std::function<void(const std::exception&)> eh);
void handleException(const std::exception& e);
void safeCall(Task task) noexcept; // auto-catch any possibly exception
// ...
};
class ThreadPool : public Executor { /* ... */ };
class Selectable {
public:
// must need
virtual int handle() const = 0;
// optional, for convenience
Scheduler* schedulee() = 0;
Scheduler::Handle*
};
class Scheduler : public Executor {
public:
class Handle;
virtual Handle* executeAfter(TimeSpan delay, Task task) = 0;
virtual Handle* executeAt(DateTime dt, Task task) = 0;
virtual Handle* executeOnWritable(Selectable* selectable, Task task) = 0;
virtual Handle* executeOnReadable(Selectable* selectable, Task task) = 0;
virtual void runLoopOnce() = 0;
virtual void breakLoop() = 0;
};
class Scheduler::Handle {
public:
void cancel();
bool isCancelled();
// ...
};
class NativeScheduler : public Scheduler {
// implements all functions based on platform-independant select() plus helpers
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment