LanguageExt.Core

LanguageExt.Core Effects Schedule

Contents

struct Duration Source #

Period of time in milliseconds. Can be used to convert between other duration like types, such as TimeSpan and Time.

Fields

field Duration Zero = new(0) Source #

Zero magnitude duration (instant)

Constructors

constructor Duration (double milliseconds) Source #

Duration constructor

Parameters

param milliseconds

Magnitude of the duration. Must be zero or a positive value

Methods

method Duration random (Duration min, Duration max, Option<int> seed = default) Source #

Random duration between the provided min and max durations.

This can be used to seed a schedule in parallel. Providing another method of de-correlation.

For example, this is a linear schedule that,

  • starts with a seed duration between 10 and 50 milliseconds

  • includes a 10% jitter, added and removed in sequence from each duration

  • recurring 5 times

    Schedule.linear(Duration.Random(10ms, 50ms)) | Schedule.decorrelate() | Schedule.recurs(5)

Three runs result in,

(25ms, 23ms, 50ms, 47ms, 72ms)
(13ms, 11ms, 25ms, 23ms, 40ms)
(28ms, 25ms, 56ms, 53ms, 87ms)

Parameters

param min

min duration

param max

max duration

param seed

optional seed

returns

random duration between min and max duration

method bool Equals (Duration other) Source #

method bool Equals (object obj) Source #

method int GetHashCode () Source #

method int CompareTo (Duration other) Source #

method string ToString () Source #

Operators

operator == (Duration a, Duration b) Source #

operator != (Duration a, Duration b) Source #

operator > (Duration a, Duration b) Source #

operator >= (Duration a, Duration b) Source #

operator < (Duration a, Duration b) Source #

operator <= (Duration a, Duration b) Source #

record Schedule Source #

Fields

field ScheduleTransformer Identity = Transform(identity) Source #

Identity or no-op schedule result transformer

field Schedule Forever = SchForever.Default Source #

Schedule that runs forever

field Schedule Never = SchNever.Default Source #

Schedule that never runs

field Schedule Once = Forever.Take(1) Source #

Schedule that runs once

field ScheduleTransformer NoDelayOnFirst = Transform(s => s.Tail.Prepend(Duration.Zero)) Source #

A schedule transformer that will enforce the first retry has no delay

field ScheduleTransformer RepeatForever = Transform(s => new SchRepeatForever(s)) Source #

Repeats the schedule forever

Methods

method Schedule TimeSeries (params Duration[] durations) Source #

Schedule constructor that recurs for the specified durations

Parameters

param durations

durations to apply

method Schedule TimeSeries (Arr<Duration> durations) Source #

Schedule constructor that recurs for the specified durations

Parameters

param durations

durations to apply

method Schedule TimeSeries (Seq<Duration> durations) Source #

Schedule constructor that recurs for the specified durations

Parameters

param durations

durations to apply

method Schedule TimeSeries (Lst<Duration> durations) Source #

Schedule constructor that recurs for the specified durations

Parameters

param durations

durations to apply

method Schedule TimeSeries (Set<Duration> durations) Source #

Schedule constructor that recurs for the specified durations

Parameters

param durations

durations to apply

method Schedule TimeSeries (HashSet<Duration> durations) Source #

Schedule constructor that recurs for the specified durations

Parameters

param durations

durations to apply

method ScheduleTransformer Transform (Func<Schedule, Schedule> transform) Source #

ScheduleTransformer constructor which provides mapping capabilities for Schedule instances

Parameters

param transform

Transformation function

returns

ScheduleTransformer

method ScheduleTransformer recurs (int times) Source #

Schedule transformer that limits the schedule to run the specified number of times

Parameters

param times

number of times

method Schedule spaced (Duration space) Source #

Schedule that recurs continuously with the given spacing

Parameters

param space

space

method Schedule linear (Duration seed, double factor = 1) Source #

Schedule that recurs continuously using a linear backoff

Parameters

param seed

seed

param factor

optional factor to apply, default 1

method Schedule exponential (Duration seed, double factor = 2) Source #

Schedule that recurs continuously using a exponential backoff

Parameters

param seed

seed

param factor

optional factor to apply, default 2

method Schedule fibonacci (Duration seed) Source #

Schedule that recurs continuously using a fibonacci based backoff

Parameters

param seed

seed

method Schedule upto (Duration max, Func<DateTime>? currentTimeFn = null) Source #

Schedule that runs for a given duration

Parameters

param max

max duration to run the schedule for

param currentTimeFn

current time function

method Schedule fixedInterval (Duration interval, Func<DateTime>? currentTimeFn = null) Source #

Schedule that recurs on a fixed interval.

If the action run between updates takes longer than the interval, then the action will be run immediately, but re-runs will not "pile up".

|-----interval-----|-----interval-----|-----interval-----|
|---------action--------||action|-----|action|-----------|

Parameters

param interval

schedule interval

param currentTimeFn

current time function

method Schedule windowed (Duration interval, Func<DateTime>? currentTimeFn = null) Source #

A schedule that divides the timeline into interval-long windows, and sleeps until the nearest window boundary every time it recurs.

For example, Windowed(10 * seconds) would produce a schedule as follows:

     10s        10s        10s       10s
|----------|----------|----------|----------|
|action------|sleep---|act|-sleep|action----|

Parameters

param interval

schedule interval

param currentTimeFn

current time function

method Schedule secondOfMinute (int second, Func<DateTime>? currentTimeFn = null) Source #

Cron-like schedule that recurs every specified second of each minute

Parameters

param second

second of the minute, will be rounded to fit between 0 and 59

param currentTimeFn

current time function

method Schedule minuteOfHour (int minute, Func<DateTime>? currentTimeFn = null) Source #

Cron-like schedule that recurs every specified minute of each hour

Parameters

param minute

minute of the hour, will be rounded to fit between 0 and 59

param currentTimeFn

current time function

method Schedule hourOfDay (int hour, Func<DateTime>? currentTimeFn = null) Source #

Cron-like schedule that recurs every specified hour of each day

Parameters

param hour

hour of the day, will be rounded to fit between 0 and 23

param currentTimeFn

current time function

method Schedule dayOfWeek (DayOfWeek day, Func<DateTime>? currentTimeFn = null) Source #

Cron-like schedule that recurs every specified day of each week

Parameters

param day

day of the week

param currentTimeFn

current time function

method ScheduleTransformer maxDelay (Duration max) Source #

A schedule transformer that limits the returned delays to max delay

Parameters

param max

max delay to return

method ScheduleTransformer maxCumulativeDelay (Duration max) Source #

Limits the schedule to the max cumulative delay

Parameters

param max

max delay to stop schedule at

method ScheduleTransformer jitter (Duration minRandom, Duration maxRandom, Option<int> seed = default) Source #

A schedule transformer that adds a random jitter to any returned delay

Parameters

param minRandom

min random milliseconds

param maxRandom

max random milliseconds

param seed

optional seed

method ScheduleTransformer jitter (double factor = 0.5, Option<int> seed = default) Source #

A schedule transformer that adds a random jitter to any returned delay

Parameters

param factor

jitter factor based on the returned delay

param seed

optional seed

method ScheduleTransformer decorrelate (double factor = 0.1, Option<int> seed = default) Source #

Transforms the schedule by de-correlating each of the durations both up and down in a jittered way

Given a linear schedule starting at 100. (100, 200, 300...) Adding de-correlation to it might produce a result like this, (103.2342, 97.123, 202.3213, 197.321...) The overall schedule runs twice as long but should be less correlated when used in parallel.

Parameters

param factor

jitter factor based on the returned delay

param seed

optional seed

method ScheduleTransformer resetAfter (Duration max) Source #

Resets the schedule after a provided cumulative max duration

Parameters

param max

max delay to reset the schedule at

method ScheduleTransformer repeat (int times) Source #

Repeats the schedule n number of times

Parameters

param times

number of times to repeat the schedule

method ScheduleTransformer intersperse (Schedule schedule) Source #

Intersperse the provided duration(s) between each duration in the schedule

Parameters

param duration

schedule to intersperse

method ScheduleTransformer intersperse (params Duration[] durations) Source #

Intersperse the provided duration(s) between each duration in the schedule

Parameters

param durations

1 or more durations to intersperse

method Schedule Spaced (Duration space) Source #

method ScheduleTransformer Recurs (int times) Source #

method Schedule Exponential (Duration seed, double factor = 2) Source #

method Schedule Fibonacci (Duration seed) Source #

record Schedule Source #

A schedule is defined as a potentially infinite stream of durations, combined with mechanisms for composing them.

Used heavily by repeat, retry, and fold with the Aff and Eff types. Use the static methods to create parts of schedulers and then union them using | or intersect them using &. Union will take the minimum of the two schedules to the length of the longest, intersect will take the maximum of the two schedules to the length of the shortest.

Examples

This example creates a schedule that repeats 5 times, with an exponential delay between each stage, starting at 10 milliseconds:

var s = Schedule.recurs(5) | Schedule.exponential(10*ms)

This example creates a schedule that repeats 5 times, with an exponential delay between each stage, starting at 10 milliseconds and with a maximum delay of 2000 milliseconds:

var s = Schedule.recurs(5) | Schedule.exponential(10*ms) | Schedule.spaced(2000*ms)

This example creates a schedule that repeats 5 times, with an exponential delay between each stage, starting at 10 milliseconds and with a minimum delay of 300 milliseconds:

var s = Schedule.recurs(5) | Schedule.exponential(10*ms) & Schedule.spaced(300*ms)

Properties

property Schedule Tail Source #

Take all but the first duration from the schedule

Methods

method IEnumerable<Duration> Run () Source #

Realise the underlying time-series of durations

Parameters

returns

The underlying time-series of durations

method Schedule Intersect (Schedule b) Source #

Intersection of two schedules. As long as they are both running it returns the max duration

Parameters

param b

Schedule b

returns

Max of schedule this and b to the length of the shortest schedule

method Schedule Union (Schedule b) Source #

Union of two schedules. As long as any are running it returns the min duration of both or a or b

Parameters

param b

Schedule b

returns

Min of schedule this and b or this or b to the length of the longest schedule

method Schedule Interleave (Schedule b) Source #

Interleave two schedules together

Parameters

param b

Schedule b

returns

Returns the two schedules interleaved together

method Schedule Append (Schedule b) Source #

Append two schedules together

Parameters

param b

Schedule b

returns

Returns the two schedules appended

method Schedule Take (int amount) Source #

Take amount durations from the Schedule

Parameters

param s

Schedule to take from

param amount

Amount ot take

returns

Schedule with amount or less durations

method Schedule Skip (int amount) Source #

Skip amount durations from the Schedule

Parameters

param s

Schedule to skip durations from

param amount

Amount ot skip

returns

Schedule with amount durations skipped

method Schedule Prepend (Duration value) Source #

Prepend a duration in-front of the rest of the scheduled durations

Parameters

param value

Duration to prepend

returns

Schedule with the duration prepended

method Schedule Map (Func<Duration, Duration> f) Source #

Functor map operation for Schedule

Parameters

param f

Mapping function

returns

Mapped schedule

method Schedule Map (Func<Duration, int, Duration> f) Source #

Functor map operation for Schedule

Parameters

param f

Mapping function

returns

Mapped schedule

method Schedule Filter (Func<Duration, bool> pred) Source #

Filter operation for Schedule

Parameters

param pred

predicate

returns

Filtered schedule

method Schedule Where (Func<Duration, bool> pred) Source #

Filter operation for Schedule

Parameters

param pred

predicate

returns

Filtered schedule

method Schedule Select (Func<Duration, Duration> f) Source #

Functor map operation for Schedule

Parameters

param f

Mapping function

returns

Mapped schedule

method Schedule Select (Func<Duration, int, Duration> f) Source #

Functor map operation for Schedule

Parameters

param f

Mapping function

returns

Mapped schedule

method Schedule Bind (Func<Duration, Schedule> f) Source #

Monad bind operation for Schedule

Parameters

param f

Bind function

returns

Chained schedule

method Schedule SelectMany (Func<Duration, Schedule> f) Source #

Monad bind operation for Schedule

Parameters

param f

Bind function

returns

Chained schedule

method Schedule SelectMany (Func<Duration, Schedule> bind, Func<Duration, Duration, Duration> project) Source #

Monad bind and project operation for Schedule

Parameters

param s

Schedule

param bind

Bind function

param project

Project function

returns

Chained schedule

Operators

operator | (Schedule a, Schedule b) Source #

operator | (Schedule a, ScheduleTransformer b) Source #

operator | (ScheduleTransformer a, Schedule b) Source #

operator & (Schedule a, Schedule b) Source #

operator & (Schedule a, ScheduleTransformer b) Source #

operator & (ScheduleTransformer a, Schedule b) Source #

operator + (Schedule a, Schedule b) Source #

class ScheduleExtensions Source #

Methods

method Schedule ToSchedule (this Seq<Duration> seq) Source #

Converts a Seq of positive durations to a schedule

Parameters

param seq

Seq of positive durations

returns

schedule

method Schedule ToSchedule (this Arr<Duration> array) Source #

Converts a Arr of positive durations to a schedule

Parameters

param array

array of positive durations

returns

schedule

method Schedule ToSchedule (this Lst<Duration> list) Source #

Converts a Lst of positive durations to a schedule

Parameters

param list

list of positive durations

returns

schedule

method Schedule ToSchedule (this Set<Duration> set) Source #

Converts a Set of positive durations to a schedule

Parameters

param set

set of positive durations

returns

schedule

method Schedule ToSchedule (this HashSet<Duration> hashSet) Source #

Converts a HashSet of positive durations to a schedule

Parameters

param hashSet

hashset of positive durations

returns

schedule

method Schedule Cons (this Duration value, Schedule s) Source #

Prepend a duration to the schedule

Parameters

param value

Duration to prepend

param s

Schedule

returns

Schedule with the duration prepended

class Prelude Source #

Methods

method Schedule intersect (Schedule a, Schedule b) Source #

Intersection of two schedules. As long as they are both running it returns the max duration

Parameters

param a

Schedule a

param b

Schedule b

returns

Max of schedule a and b to the length of the shortest schedule

method Schedule union (Schedule a, Schedule b) Source #

Union of two schedules. As long as any are running it returns the min duration of both or a or b

Parameters

param a

Schedule a

param b

Schedule b

returns

Min of schedule a and b or a or b to the length of the longest schedule

method Schedule interleave (Schedule a, Schedule b) Source #

Interleave two schedules together

Parameters

param a

Schedule a

param b

Schedule b

returns

Returns the two schedules interleaved together

method Schedule append (Schedule a, Schedule b) Source #

Append two schedules together

Parameters

param a

Schedule a

param b

Schedule b

returns

Returns the two schedules appended

method Schedule take (Schedule s, int amount) Source #

Take amount durations from the Schedule

Parameters

param s

Schedule to take from

param amount

Amount ot take

returns

Schedule with amount or less durations

method Schedule skip (Schedule s, int amount) Source #

Skip amount durations from the Schedule

Parameters

param s

Schedule to skip durations from

param amount

Amount ot skip

returns

Schedule with amount durations skipped

method Schedule tail (Schedule s) Source #

Take all but the first duration from the schedule

method Schedule map (Schedule s, Func<Duration, Duration> f) Source #

Functor map operation for Schedule

Parameters

param s

Schedule

param f

Mapping function

returns

Mapped schedule

method Schedule filter (Schedule s, Func<Duration, bool> pred) Source #

Filter operation for Schedule

Parameters

param s

Schedule

param pred

predicate

returns

Filtered schedule

method Schedule bind (Schedule s, Func<Duration, Schedule> f) Source #

Monad bind operation for Schedule

Parameters

param s

Schedule

param f

Bind function

returns

Chained schedule

struct ScheduleTransformer Source #

Transforms a schedule into another schedule

Methods

method Schedule Apply (Schedule schedule) Source #

Apply a schedule to the transformer

Parameters

param schedule

Schedule to run through the transformer

returns

Schedule that has been run through the transformer

Operators

operator + (ScheduleTransformer f, ScheduleTransformer g) Source #

Compose the two transformers into one

Parameters

param f

First transformer to run in the composition

param g

Second transformer to run in the composition

returns

composition of the 2 transformers