Documentation
¶
Overview ¶
Package run is the collection of flow architectural blocks.
Each function in the package is middleware which always takes at least one floc.Job to run and constructs and returns another floc.Job. That allows to organize jobs in any combination and in result is only one floc.Job which can be run with floc.Run().
Index ¶
- func Background(job floc.Job) floc.Job
- func Delay(delay time.Duration, job floc.Job) floc.Job
- func Else(job floc.Job) floc.Job
- func If(predicate floc.Predicate, jobs ...floc.Job) floc.Job
- func IfNot(predicate floc.Predicate, jobs ...floc.Job) floc.Job
- func Loop(job floc.Job) floc.Job
- func Parallel(jobs ...floc.Job) floc.Job
- func Repeat(times int, job floc.Job) floc.Job
- func Sequence(jobs ...floc.Job) floc.Job
- func Then(job floc.Job) floc.Job
- func Wait(predicate floc.Predicate, sleep time.Duration) floc.Job
- func While(predicate floc.Predicate, job floc.Job) floc.Job
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Background ¶
func Background(job floc.Job) floc.Job
Background starts the job in it's own goroutine. The function does not track the lifecycle of the job started and does no synchronization with it therefore the job running in background may remain active even if the flow is finished. The function assumes the job is aware of the flow state and/or synchronization and termination of it is implemented outside.
floc.Run(run.Background( func(ctx floc.Context, ctrl floc.Control) error { for !ctrl.IsFinished() { fmt.Println(time.Now()) } return nil } })
Summary:
- Run jobs in goroutines : YES
- Wait all jobs finish : NO
- Run order : SINGLE
Diagram:
--+-----------> | +-->[JOB]
func Delay ¶
Delay does delay before starting the job.
Summary:
- Run jobs in goroutines : NO
- Wait all jobs finish : YES
- Run order : SINGLE
Diagram:
--(DELAY)-->[JOB]-->
func Else ¶
func Else(job floc.Job) floc.Job
Else just returns the job unmodified. Else is used for expressiveness and can be omitted.
Summary:
- Run jobs in goroutines : N/A
- Wait all jobs finish : N/A
- Run order : N/A
Diagram:
----[JOB]--->
func If ¶
func If(predicate floc.Predicate, jobs ...floc.Job) floc.Job
If runs the first job if the condition is met and runs the second job, if it's passed, if the condition is not met. The function panics if no or more than two jobs are given.
For expressiveness Then() and Else() can be used.
flow := run.If(testSomething, run.Then(doSomething), run.Else(doSomethingElse), )
Summary:
- Run jobs in goroutines : NO
- Wait all jobs finish : YES
- Run order : SINGLE
Diagram:
+----->[JOB_1]---+ | YES | --(CONDITION MET?)--+ +--> | NO | +----->[JOB_2]---+
func IfNot ¶
func IfNot(predicate floc.Predicate, jobs ...floc.Job) floc.Job
IfNot runs the first job if the condition is not met and runs the second job, if it's passed, if the condition is met. The function panics if no or more than two jobs are given.
For expressiveness Then() and Else() can be used.
flow := run.IfNot(testSomething, run.Then(doSomething), run.Else(doSomethingElse), )
Summary:
- Run jobs in goroutines : NO
- Wait all jobs finish : YES
- Run order : SINGLE
Diagram:
+----->[JOB_1]---+ | NO | --(CONDITION MET?)--+ +--> | YES | +----->[JOB_2]---+
func Loop ¶
func Loop(job floc.Job) floc.Job
Loop repeats running the job forever.
Summary:
- Run jobs in goroutines : NO
- Wait all jobs finish : YES
- Run order : SINGLE
Diagram:
+----------+ | | V | ----->[JOB]--+
func Parallel ¶
func Parallel(jobs ...floc.Job) floc.Job
Parallel runs jobs in their own goroutines and waits until all of them finish.
Summary:
- Run jobs in goroutines : YES
- Wait all jobs finish : YES
- Run order : PARALLEL
Diagram:
+-->[JOB_1]--+ | | --+--> .. --+--> | | +-->[JOB_N]--+
func Repeat ¶
func Repeat(times int, job floc.Job) floc.Job
Repeat repeats running the job for N times.
Summary:
- Run jobs in goroutines : NO
- Wait all jobs finish : YES
- Run order : SINGLE
Diagram:
NO +-----------[JOB]<---------+ | | V | YES ----(ITERATED COUNT TIMES?)--+---->
func Sequence ¶
func Sequence(jobs ...floc.Job) floc.Job
Sequence runs jobs sequentially, one by one.
Summary:
- Run jobs in goroutines : NO
- Wait all jobs finish : YES
- Run order : SEQUENCE
Diagram:
-->[JOB_1]-...->[JOB_N]-->
func Then ¶
func Then(job floc.Job) floc.Job
Then just returns the job unmodified. Then is used for expressiveness and can be omitted.
Summary:
- Run jobs in goroutines : N/A
- Wait all jobs finish : N/A
- Run order : N/A
Diagram:
----[JOB]--->
func Wait ¶
Wait waits until the condition is met. The function falls into sleep with the duration given between condition checks. The function does not run any job actually and just repeatedly checks predicate's return value. When the predicate returns true the function finishes.
Summary:
- Run jobs in goroutines : N/A
- Wait all jobs finish : N/A
- Run order : N/A
Diagram:
NO +------(SLEEP)------+ | | V | YES ----(CONDITION MET?)--+----->
Types ¶
This section is empty.