task

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: Apache-2.0 Imports: 4 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(queue Queue, ctx context.Context) error

Run runs all tasks in the Queue until either the queue is empty or a task returns an error

Types

type ContextProvider added in v1.2.0

type ContextProvider func(context.Context) (context.Context, error)

ContextProvider provides a context based on another, used by Using

type Queue

type Queue interface {
	AddTask(t Task) Queue
	AddPriorityTask(priority int, task Task) Queue
}

func GetQueue

func GetQueue(ctx context.Context) Queue

GetQueue returns the Queue contained in this Context

func NewQueue

func NewQueue() Queue

type Task

type Task func(ctx context.Context) error

Task is a task that the Generator must run once all other Handler's have been run. They are usually tasks created by those Handlers.

func Of

func Of(tasks ...Task) Task

Of creates a new Task forming a chain of the provided tasks

func (Task) Do

func (a Task) Do(ctx context.Context) error

func (Task) Guard added in v1.2.0

func (a Task) Guard() Task

Guard wraps a task so that any error or panic returned by that task is ignored. It is used when you don't want the task to stop all other processing.

func (Task) Queue

func (a Task) Queue(tasks ...Task) Task

Queue will defer the queued task onto the underlying Queue. If one or more tasks are provided then they will be queued if the flow reaches this location. If none, then the current task will be queued when run.

func (Task) QueueWithPriority

func (a Task) QueueWithPriority(priority int, tasks ...Task) Task

QueueWithPriority will defer the queued task onto the underlying Queue with a priority If one or more tasks are provided then they will be queued if the flow reaches this location. If none, then the current task will be queued when run.

func (Task) RequireValue

func (a Task) RequireValue(key string) Task

RequireValue ensures that a key is defined within the current Context.

func (Task) RunOnce

func (a Task) RunOnce(f *bool, t Task) Task

RunOnce will invoke a task exactly once. It uses a pointer to a boolean to store this state. It's useful for simple tasks but should be treated as Deprecated. Currently, here as Book still uses it as it only works for one Book not multiple books.

func (Task) Then

func (a Task) Then(b Task) Task

Then joins two tasks together

func (Task) Using added in v1.2.0

func (a Task) Using(f ContextProvider) Task

Using allows a ContextProvider to be used in a task, an alternate method to UsingValue

func (Task) UsingValue added in v1.2.0

func (a Task) UsingValue(key string, f ValueProvider) Task

UsingValue adds a named value to the context before passing it to the parent task

func (Task) WithContext

func (a Task) WithContext(srcCtx context.Context, keys ...string) Task

WithContext copies the specified keys from a source context. It's the equivalent of WithValue(key,srcCtx.Value(key))

func (Task) WithValue

func (a Task) WithValue(key string, value interface{}) Task

WithValue adds a named value to the context

type ValueProvider added in v1.2.0

type ValueProvider func(context.Context) (interface{}, error)

ValueProvider provides a value at runtime, used with UsingValue

Jump to

Keyboard shortcuts

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