run

package
v2.0.0-...-072ea80 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2020 License: MIT Imports: 3 Imported by: 1

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

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

func Delay(delay time.Duration, job floc.Job) floc.Job

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

func Wait(predicate floc.Predicate, sleep time.Duration) floc.Job

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?)--+----->

func While

func While(predicate floc.Predicate, job floc.Job) floc.Job

While repeats running the job while the condition is met.

Summary:

  • Run jobs in goroutines : NO
  • Wait all jobs finish : YES
  • Run order : SINGLE

Diagram:

                  YES
  +-------[JOB]<------+
  |                   |
  V                   | NO
----(CONDITION MET?)--+---->

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL