parallelisation

package
v1.77.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 6 Imported by: 5

Documentation

Overview

Package parallelisation defines a module for `Concurrency`

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetermineContextError

func DetermineContextError(ctx context.Context) error

DetermineContextError determines what the context error is if any.

func Parallelise

func Parallelise(argList interface{}, action func(arg interface{}) (interface{}, error), resultType reflect.Type) (results interface{}, err error)

Parallelise parallelises an action over as many goroutines as specified by the argList and retrieves all the results when all the goroutines are done.

func RunActionWithParallelCheck

func RunActionWithParallelCheck(ctx context.Context, action func(ctx context.Context) error, checkAction func(ctx context.Context) bool, checkPeriod time.Duration) error

RunActionWithParallelCheck runs an action with a check in parallel The function performing the check should return true if the check was favourable; false otherwise. If the check did not have the expected result and the whole function would be cancelled.

func RunActionWithTimeout

func RunActionWithTimeout(blockingAction func(stop chan bool) error, timeout time.Duration) (err error)

RunActionWithTimeout runs an action with timeout

func RunActionWithTimeoutAndCancelStore

func RunActionWithTimeoutAndCancelStore(ctx context.Context, timeout time.Duration, store *CancelFunctionStore, blockingAction func(context.Context) error) error

RunActionWithTimeoutAndCancelStore runs an action with timeout The cancel store is used just to register the cancel function so that it can be called on Cancel.

func RunActionWithTimeoutAndContext

func RunActionWithTimeoutAndContext(ctx context.Context, timeout time.Duration, blockingAction func(context.Context) error) error

RunActionWithTimeoutAndContext runs an action with timeout blockingAction's context will be cancelled on exit.

func SafeSchedule added in v1.40.0

func SafeSchedule(ctx context.Context, period time.Duration, offset time.Duration, f func(context.Context, time.Time))

SafeSchedule calls function `f` regularly with a `period` and an `offset`, similarly to Schedule but with context control.

func SafeScheduleAfter added in v1.40.0

func SafeScheduleAfter(ctx context.Context, offset time.Duration, f func(context.Context, time.Time))

SafeScheduleAfter calls once function `f` after `offset` similarly to ScheduleAfter but stops the function is controlled by the context

func Schedule

func Schedule(ctx context.Context, period time.Duration, offset time.Duration, f func(time.Time))

Schedule calls function `f` regularly with a `period` and an `offset`.

func ScheduleAfter added in v1.1.0

func ScheduleAfter(ctx context.Context, offset time.Duration, f func(time.Time))

ScheduleAfter calls once function `f` after `offset`

func SleepWithContext

func SleepWithContext(ctx context.Context, delay time.Duration)

SleepWithContext performs an interruptable sleep Similar to time.Sleep() but also responding to context cancellation instead of blocking for the whole length of time.

func SleepWithInterruption

func SleepWithInterruption(stop chan bool, delay time.Duration)

SleepWithInterruption performs an interruptable sleep Similar to time.Sleep() but also interrupting when requested instead of blocking for the whole length of time.

Types

type CancelFunctionStore

type CancelFunctionStore struct {
	// contains filtered or unexported fields
}

func NewCancelFunctionsStore

func NewCancelFunctionsStore() *CancelFunctionStore

func (*CancelFunctionStore) Cancel

func (s *CancelFunctionStore) Cancel()

func (*CancelFunctionStore) Len

func (s *CancelFunctionStore) Len() int

func (*CancelFunctionStore) RegisterCancelFunction

func (s *CancelFunctionStore) RegisterCancelFunction(cancel ...context.CancelFunc)

Jump to

Keyboard shortcuts

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