42 lines
991 B
C++
42 lines
991 B
C++
#include <Void/Scheduler/Scheduler.hpp>
|
|
|
|
#include <cstdlib>
|
|
|
|
int main()
|
|
{
|
|
Void::Time::ManualClock mono{};
|
|
auto sched = Void::Scheduler::Scheduler::create(
|
|
Void::Scheduler::SchedulerOptions{.monotonic_clock = &mono});
|
|
if (!sched.has_value()) {
|
|
return EXIT_FAILURE;
|
|
}
|
|
int ran = 0;
|
|
if (!sched->register_handler(
|
|
"ping",
|
|
[&](const Void::Scheduler::OccurrenceContext&,
|
|
std::span<const std::byte>,
|
|
Void::Async::OperationOptions)
|
|
-> Void::Scheduler::Result<void> {
|
|
++ran;
|
|
return {};
|
|
})
|
|
.has_value()) {
|
|
return EXIT_FAILURE;
|
|
}
|
|
Void::Scheduler::JobSpec spec{};
|
|
spec.id = "j1";
|
|
spec.handler_id = "ping";
|
|
spec.schedule = Void::Scheduler::Schedule::one_shot_monotonic(mono.now());
|
|
if (!sched->add_job(spec).has_value()) {
|
|
return EXIT_FAILURE;
|
|
}
|
|
auto count = sched->tick();
|
|
if (!count.has_value() || *count != 1U || ran != 1) {
|
|
return EXIT_FAILURE;
|
|
}
|
|
if (!sched->close_and_join().has_value()) {
|
|
return EXIT_FAILURE;
|
|
}
|
|
return EXIT_SUCCESS;
|
|
}
|