Skip to content

Commit b559e40

Browse files
committed
fixed issue with msvc
updated README.md
1 parent a89cc36 commit b559e40

2 files changed

Lines changed: 36 additions & 17 deletions

File tree

README.md

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ using namespace std::chrono_literals;
3232
auto main() -> int {
3333
oryx::chron::Scheduler scheduler;
3434

35-
scheduler.AddSchedule("Task-1", "* * * * * ?", [](auto info) { std::cout << info.name << " called with delay" << task.delay << "\n"; });
35+
scheduler.AddSchedule("Task-1", "* * * * * ?",
36+
[](auto info) { std::cout << info.name << " called with delay " << info.delay << "\n"; });
3637
for (;;) {
3738
scheduler.Tick();
3839
std::this_thread::sleep_for(1s);
@@ -49,14 +50,13 @@ In order to trigger execution of callbacks one must call `oryx::chron::Scheduler
4950
#include <iostream>
5051

5152
#include <oryx/chron.hpp>
52-
#include "oryx/chron/task.hpp"
5353

5454
using namespace std::chrono_literals;
5555

5656
auto main() -> int {
5757
oryx::chron::Scheduler scheduler;
5858

59-
scheduler.AddSchedule("Task-1", "* * * * * ?", [](const oryx::chron::TaskInfo& info) {
59+
scheduler.AddSchedule("Task-1", "* * * * * ?", [](auto info) {
6060
if (info.delay >= 1s) {
6161
std::cout << info.name << ": my scheduler is ticking to slow\n";
6262
}
@@ -72,20 +72,40 @@ auto main() -> int {
7272

7373
### Adding a batch of schedules at once
7474

75-
#### TODO
75+
```cpp
76+
#include <thread>
77+
#include <iostream>
78+
#include <cassert>
79+
80+
#include <oryx/chron.hpp>
7681

82+
using namespace std::chrono_literals;
7783

84+
auto main() -> int {
85+
oryx::chron::Scheduler scheduler;
7886

79-
### Removing schedules from `oryx::chron::Scheduler`
87+
assert(scheduler.AddScheduleBatch([](auto add_schedule) {
88+
auto task = [](auto info) { std::cout << info.name << " was called\n"; };
89+
for (auto i = 0; i < 20; i++) {
90+
assert(add_schedule(std::to_string(i), "*/2 * * * * ?", task));
91+
}
92+
}));
8093

81-
`oryx::chron::Scheduler` offers two convenient functions to remove schedules:
94+
for (;;) {
95+
scheduler.Tick();
96+
std::this_thread::sleep_for(1s);
97+
}
8298

83-
- `ClearSchedules()` will remove all schedules
84-
- `RemoveSchedule(std::string)` will remove a specific schedule
99+
return 0;
100+
}
101+
```
85102

86-
For example, `scheduler.RemoveSchedule("Hello from Cron")` will remove the previously added task.
103+
### Removing schedules
87104

105+
`oryx::chron::Scheduler` offers two convenient functions to remove schedules:
88106

107+
- `ClearSchedules` will remove all schedules
108+
- `RemoveSchedule` will remove a specific schedule
89109

90110
### ThreadSafe Scheduler
91111

@@ -106,26 +126,25 @@ using namespace oryx::chron;
106126

107127
std::atomic<bool> stop_requested{};
108128

109-
void Ticker(MTScheduler<UTCClock>& scheduler) {
129+
void Ticker(auto& scheduler) {
110130
while (!stop_requested) {
111131
scheduler.Tick();
112-
std::this_thread::sleep_for(1s);
132+
std::this_thread::sleep_for(50ms);
113133
}
114134
}
115135

116136
auto main() -> int {
117137
signal(SIGINT, [](int sig) { stop_requested = true; });
118138

119139
MTScheduler<UTCClock> scheduler{};
120-
std::thread worker{Ticker, std::ref(scheduler)};
140+
std::thread worker{Ticker<decltype(scheduler)>, std::ref(scheduler)};
121141
uint64_t counter{};
122142
std::string task_name{};
123143
while (!stop_requested) {
124144
task_name = "Task-" + std::to_string(counter++);
125-
scheduler.AddSchedule(task_name, "* * * * * ?",
126-
[](TaskInfo info) { std::cout << info.name << ": Called\n"; });
145+
scheduler.AddSchedule(task_name, "* * * * * ?", [](TaskInfo info) { std::cout << info.name << ": Called\n"; });
127146
std::cout << "Scheduled: " << task_name << "\n";
128-
std::this_thread::sleep_for(1s);
147+
std::this_thread::sleep_for(50ms);
129148
}
130149

131150
worker.join();
@@ -145,7 +164,7 @@ If you you are frequently parsing a lot of similar expressions you can speed up
145164

146165
The following clocks are available for the scheduler:
147166

148-
- (default) `LocalClock` offsets by system_clocks time
167+
- `LocalClock` (default) offsets by operating systems time
149168
- `UTCClock` offsets by 0
150169
- `TzClock` offsets by 0 until a valid timezone has been set with `TrySetTimezone`
151170

include/oryx/chron/details/parser.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ struct Parser {
156156
if constexpr (std::is_convertible_v<decltype(part), std::string_view>)
157157
return ConvertFromStringRangeToNumberRange<T>(part, numbers);
158158
else
159-
return ConvertFromStringRangeToNumberRange(std::string_view(part.begin(), part.size()), numbers);
159+
return ConvertFromStringRangeToNumberRange(std::string_view(&*part.begin(), part.size()), numbers);
160160
});
161161
}
162162

0 commit comments

Comments
 (0)