concurrent

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallbackSerializer

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

CallbackSerializer provides a mechanism to schedule callbacks in a synchronized manner. It provides a FIFO guarantee on the order of execution of scheduled callbacks. New callbacks can be scheduled by invoking the Schedule() method.

This type is safe for concurrent access.

func NewCallbackSerializer

func NewCallbackSerializer(ctx context.Context) *CallbackSerializer

NewCallbackSerializer returns a new CallbackSerializer instance. The provided context will be passed to the scheduled callbacks. Users should cancel the provided context to shutdown the CallbackSerializer. It is guaranteed that no callbacks will be added once this context is canceled, and any pending un-run callbacks will be executed before the serializer is shut down.

func (*CallbackSerializer) Done

func (cs *CallbackSerializer) Done() <-chan struct{}

Done returns a channel that is closed after the context passed to NewCallbackSerializer is canceled and all callbacks have been executed.

func (*CallbackSerializer) ScheduleOr

func (cs *CallbackSerializer) ScheduleOr(f func(ctx context.Context), onFailure func())

ScheduleOr schedules the provided callback function f to be executed in the order it was added. If the context passed to NewCallbackSerializer has been canceled before this method is called, the onFailure callback will be executed inline instead.

Callbacks are expected to honor the context when performing any blocking operations, and should return early when the context is canceled.

func (*CallbackSerializer) TrySchedule

func (cs *CallbackSerializer) TrySchedule(f func(ctx context.Context))

TrySchedule tries to schedules the provided callback function f to be executed in the order it was added. This is a best-effort operation. If the context passed to NewCallbackSerializer was canceled before this method is called, the callback will not be scheduled.

Callbacks are expected to honor the context when performing any blocking operations, and should return early when the context is canceled.

Jump to

Keyboard shortcuts

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