Documentation ¶
Overview ¶
Package floc allows to orchestrate goroutines with ease. The goal of the project is to make the process of running goroutines in parallel and synchronizing them easy.
Floc follows for objectives:
-- Easy to use functional interface.
-- Better control over execution with one entry point and one exit point.
-- Simple parallelism and synchronization of jobs.
-- As little overhead, in comparison to direct use of goroutines and sync primitives, as possible.
The package categorizes middleware used for architect flows in subpackages.
-- `guard` contains middleware which help protect flow from falling into panic or unpredicted behavior.
-- `pred` contains some basic predicates for AND, OR, NOT logic.
-- `run` provides middleware for designing flow, i.e. for running job sequentially, in parallel, in background and so on.
-- `errors` all error types used in the package.
Here is a quick example of what the package capable of.
// The flow computes something complex and does writing results in // background. flow := run.Sequence( run.Background(WriteToDisk), run.While(pred.Not(TestComputed), run.Sequence( run.Parallel( ComputeSomething, ComputeSomethingElse, guard.Panic(ComputeDangerousThing), ), run.Parallel( PrepareForWrite, UpdateComputedFlag, ), )), CompleteWithSuccess, ) // The entry point: produce the result. result, data, err := floc.Run(flow) // The exit point: consume the result. if err != nil { fmt.Println(err) } else if result.IsCompleted() { fmt.Println(data) } else { fmt.Printf("Finished with result %s and data %v", result.String(), data) }
Index ¶
- type Context
- type Control
- type Job
- type Predicate
- type Releaser
- type Result
- func (result Result) IsCanceled() bool
- func (result Result) IsCompleted() bool
- func (result Result) IsFailed() bool
- func (result Result) IsFinished() bool
- func (result Result) IsNone() bool
- func (result Result) IsValid() bool
- func (result Result) Mask() ResultMask
- func (result Result) String() string
- type ResultMask
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context interface { Releaser // Ctx returns the underlying context. Ctx() context.Context // UpdateCtx sets the new underlying context. UpdateCtx(ctx context.Context) // Done returns a channel that's closed when the flow done. // Successive calls to Done return the same value. Done() <-chan struct{} // Value returns the value associated with this context for key, // or nil if no value is associated with key. Value(key interface{}) (value interface{}) // Create a new context with value and make it the current. // This is an equivalent to. // // oldCtx := ctx.Ctx() // newCtx := context.WithValue(oldCtx, key, value) // ctx.UpdateCtx(newCtx) // AddValue(key, value interface{}) }
Context provides safe access to the underlying context. For more details on the underlying context see https://golang.org/pkg/context/#Context.
func BorrowContext ¶
BorrowContext constructs new instance from the context given. The function panics if the context given is nil.
type Control ¶
type Control interface { Releaser // Complete finishes the flow with success status and stops // execution of further jobs if any. Complete(data interface{}) // Cancel cancels the execution of the flow. Cancel(data interface{}) // Fail cancels the execution of the flow with error. Fail(data interface{}, err error) // IsFinished tests if execution of the flow is either completed or canceled. IsFinished() bool // Result returns the result code and the result data of the flow. The call // to the function is effective only if the flow is finished. Result() (result Result, data interface{}, err error) }
Control allows to control execution of the flow.
func NewControl ¶
NewControl constructs Control instance from context given. The function panics if the context given is nil.
type Releaser ¶
type Releaser interface {
// Release should be called once when the object is not needed anymore.
Release()
}
Releaser is responsible for releasing underlying resources.
type Result ¶
type Result int32
Result identifies the result of execution.
Possible results.
func (Result) IsCanceled ¶
IsCanceled tests if the result is Canceled.
func (Result) IsCompleted ¶
IsCompleted tests if the result is Completed.
func (Result) IsFinished ¶
IsFinished tests if the result is either Completed or Canceled or Failed.
func (Result) Mask ¶
func (result Result) Mask() ResultMask
Mask constructs ResultMask with only one result masked.
type ResultMask ¶
type ResultMask Result
ResultMask is the mask of possible results.
func NewResultMask ¶
func NewResultMask(mask Result) ResultMask
NewResultMask constructs new instance from the mask given.
func (ResultMask) IsEmpty ¶
func (mask ResultMask) IsEmpty() bool
IsEmpty returns true if no result is masked.
func (ResultMask) IsMasked ¶
func (mask ResultMask) IsMasked(result Result) bool
IsMasked tests if the result is masked.
func (ResultMask) String ¶
func (mask ResultMask) String() string
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package errors defines error types used in the package.
|
Package errors defines error types used in the package. |
Package guard contains middleware capable to protect execution of flow from crashing or from unpredicted behavior.
|
Package guard contains middleware capable to protect execution of flow from crashing or from unpredicted behavior. |
Package pred provides predicates for basic logic operations.
|
Package pred provides predicates for basic logic operations. |
Package run is the collection of flow architectural blocks.
|
Package run is the collection of flow architectural blocks. |