sleep

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDynamicReader

func NewDynamicReader[T any](args NewDynamicReaderArgs[T]) core.Reader[T]

NewDynamicReader returns a reader which wraps args.Reader with sleep/delay, the minimum duration being set with args.Delay.

Unlike NewStaticReader, this one has a couple extra properties. Firstly it tries to adjust the sleep duration to a constant args.Delay, it does so by subtracting args.Delay by the time it took to read from args.Reader. Secondly, you may set ctx value "bounds" if you know how many times args.Reader may be called before io.EOF, in that case the whole stream will be read in approximately args.Delay. This is useful if you want a complete ETL pipeline to take a specific amount of time.

Examples (interactive):

func NewDynamicWriter

func NewDynamicWriter[T any](args NewDynamicWriterArgs[T]) core.Writer[T]

NewDynamicWriter returns a Writer which writes to args.Writer and then sleeps for the duration defined with args.Delay, or until ctx is done.

Unlike NewStaticWriter, this one has a couple extra properties. Firstly it tries to adjust the sleep duration to a constant args.Delay, it does so by subtracting args.Delay by the time it took to write to args.Writer. Secondly, you may set ctx value "bounds" if you know how many things there are to write and you want to write _all_ items in args.Delay amount of time. This is useful if you want a complete ETL pipeline to take a specific amount of time.

Examples (interactive):

func NewStaticReader

func NewStaticReader[T any](args NewStaticReaderArgs[T]) core.Reader[T]

NewStaticReader returns a reader which wraps args.Reader with sleep/delay, the duration being set with args.Delay. When reading from the returned reader, the operation happens either after args.Delay has elapsed, or if ctx is done.

Examples (interactive):

func NewStaticWriter

func NewStaticWriter[T any](args NewStaticWriterArgs[T]) core.Writer[T]

NewStaticWriter returns a Writer which writes to args.Writer and then sleeps for the duration defined with args.Delay, or until ctx is done.

Examples (interactive):

Types

type NewDynamicReaderArgs

type NewDynamicReaderArgs[T any] struct {
	Reader core.Reader[T]
	Delay  time.Duration
}

type NewDynamicWriterArgs

type NewDynamicWriterArgs[T any] struct {
	Writer core.Writer[T]
	Delay  time.Duration
}

type NewStaticReaderArgs

type NewStaticReaderArgs[T any] struct {
	Reader core.Reader[T]
	Delay  time.Duration
}

type NewStaticWriterArgs

type NewStaticWriterArgs[T any] struct {
	Writer core.Writer[T]
	Delay  time.Duration
}

Jump to

Keyboard shortcuts

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