Skip to content

Commit

Permalink
example added
Browse files Browse the repository at this point in the history
  • Loading branch information
pczekaj99 committed Dec 6, 2023
1 parent b4f6af1 commit 68302b0
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions docs/utils/threading/worker-pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,26 @@ void CFrontPanel::startBlinkTimer(int numberOfBlinkRepeats)
}
```

Below is another example of using it.
Below is test example of using it.
```cpp
void ScheduleJobs(Core::ProxyType<IDispatch>& job, const uint16_t scheduledTime)
{
InsertJobData(job, scheduledTime);
_parent.Schedule(Core::Time::Now().Add(scheduledTime), job);
}
void RescheduleJobs(Core::ProxyType<IDispatch>& job, const uint16_t scheduledTime)
{
InsertJobData(job, scheduledTime);
_parent.Reschedule(Core::Time::Now().Add(scheduledTime), job);
}
void test_scheduler(Core::ProxyType<IDispatch> job) {
// Schedule the job to run 5 seconds from now
Core::Time scheduledTime = Core::Time::Now() + Core::TimeSpan::FromSeconds(5);
_scheduler.Schedule(scheduledTime, job);

// Wait for a while to see the scheduled job execution
Core::Thread::Sleep(Core::TimeSpan::FromSeconds(10));

// Reschedule the job to run 10 seconds from now
Core::Time rescheduledTime = Core::Time::Now() + Core::TimeSpan::FromSeconds(10);
_scheduler.Reschedule(rescheduledTime, job);

// Wait for a while to see the rescheduled job execution
Core::Thread::Sleep(Core::TimeSpan::FromSeconds(15));

// Revoke the job (cancel its execution)
_scheduler.Revoke(job);
}
```
For more examples you can check `Thunder/Tests/unit/core/test_workerpool.cpp` file.

0 comments on commit 68302b0

Please sign in to comment.