Say when something should run, as data.
A Schedule is a stream of durations. Compose it, iterate it, await it, and never start a thread.
🏃 Getting Started | 📚 Documentation
Schedules are a common requirement when building software. Whenever you need some operation to repeat at some configured cadence, a way to encode that is needed.
The standard abstraction that many developers would be familiar with is Cron. This is a job scheduler that comes paired with its own little language, crontab, that says how the job repeats.
Eon exposes a type called Schedule, that is a modern alternative
to Cron. It is not concerned with how it's executed; only the cadence at which
an execution engine could run it.
It's an immutable blueprint; a potentially infinite stream of durations that can be iterated and potentially awaited.
// a schedule that emits 5 durations, each 2 seconds long
Schedule schedule =
Schedule.Spaced(TimeSpan.FromSeconds(2)) & Schedule.Recurs(5);
// a Schedule is an IEnumerable<Duration>, so the work is a plain loop
// and each duration is awaited after it
foreach(Duration duration in schedule)
{
// some operation
var result = await SomeService();
// now wait 2 seconds
await duration;
}Schedules are composed from combinators, so extending Schedule is rarely
necessary. The combinators are documented on the site.
Where that is not enough, a custom IEnumerator<Duration> is all it takes.
For more details/information have a look at the test projects or create an issue.