Skip to content

Commit

Permalink
Made compatible with C++11. No need for C++14 requirement if only usi…
Browse files Browse the repository at this point in the history
…ng chrono_literals from it.
  • Loading branch information
Bosma committed May 27, 2017
1 parent 107f710 commit 0876102
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.7)
project(BosmaScheduler)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 11)

# threads
set(THREADS_PREFER_PTHREAD_FLAG ON)
Expand Down
1 change: 0 additions & 1 deletion Cron.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace Bosma {
using Clock = std::chrono::system_clock;
using namespace std::chrono_literals;

inline void add(std::tm &tm, std::chrono::nanoseconds time) {
auto tp = Clock::from_time_t(std::mktime(&tm));
Expand Down
2 changes: 1 addition & 1 deletion Scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Bosma {
explicit InTask(std::function<void()> &&f) : Task(std::move(f)) {}

// dummy time_point because it's not used
Clock::time_point get_new_time() const override { return Clock::time_point(0ns); }
Clock::time_point get_new_time() const override { return Clock::time_point(std::chrono::nanoseconds(0)); }
};

class EveryTask : public Task {
Expand Down
12 changes: 5 additions & 7 deletions example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "Scheduler.h"

using namespace std::chrono_literals;

void message(const std::string &s) {
std::cout << s << std::endl;
}
Expand All @@ -19,15 +17,15 @@ int main() {
Bosma::Scheduler s(max_n_threads);

// every second call message("every second")
s.every(1s, message, "every second");
s.every(std::chrono::seconds(1), message, "every second");

// in one minute
s.in(1min, []() { std::cout << "in one minute" << std::endl; });
s.in(std::chrono::minutes(1), []() { std::cout << "in one minute" << std::endl; });

// in one second run lambda, then wait a second, run lambda, and so on
// different from every in that multiple instances of the function will not be run concurrently
s.interval(1s, []() {
std::this_thread::sleep_for(5s);
s.interval(std::chrono::seconds(1), []() {
std::this_thread::sleep_for(std::chrono::seconds(5));
std::cout << "once every 6s" << std::endl;
});

Expand All @@ -43,5 +41,5 @@ int main() {
s.cron("5 0 * * *", []() { std::cout << "every day 5 minutes after midnight" << std::endl; });

// destructor of Bosma::Scheduler will cancel all schedules but finish any tasks currently running
std::this_thread::sleep_for(30min);
std::this_thread::sleep_for(std::chrono::minutes(10));
}

0 comments on commit 0876102

Please sign in to comment.