effect

package
v1.23.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer holds a set of effect and rollback functions that can be invoked as a batch with a defined order. Once either Apply or Cancel is called, all buffered effects are cleared. This type is not threadsafe. The zero-value of a Buffer is a valid state.

func (*Buffer) Apply

func (b *Buffer) Apply(ctx context.Context)

Apply invokes the buffered effect functions in the order that they were added to this Buffer.

func (*Buffer) Cancel

func (b *Buffer) Cancel(ctx context.Context)

Cancel invokes the buffered rollback functions in the reverse of the order that they were added to this Buffer.

func (*Buffer) OnAfterCommit

func (b *Buffer) OnAfterCommit(effect func(context.Context))

OnAfterCommit adds the provided effect function to set of such functions to be invoked when Buffer.Apply is called.

func (*Buffer) OnAfterRollback

func (b *Buffer) OnAfterRollback(effect func(context.Context))

OnAfterRollback adds the provided effect function to set of such functions to be invoked when Buffer.Cancel is called.

type Controller

type Controller interface {
	OnAfterCommit(func(context.Context))
	OnAfterRollback(func(context.Context))
}

func Immediate

func Immediate(ctx context.Context) Controller

Immediate returns an effects.Controller that executes effects immediately upon insertion. Useful in contexts where you don't actually want to delay effect application and in tests.

Jump to

Keyboard shortcuts

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