types

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregationWithCache

type AggregationWithCache[T comparable] struct {
	Aggregation []T
	Cache       map[T]bool
}

type AggregationWithCacheAndCounter

type AggregationWithCacheAndCounter[T comparable] struct {
	Aggregation []T
	Cache       map[T]bool
	Counter     int64
}

type AggregationWithCounter

type AggregationWithCounter[T any] struct {
	Aggregation T
	Counter     int64
}

type ComplexNumber

type ComplexNumber interface {
	constraints.Complex
}

type Future

type Future[T any] struct {
	// contains filtered or unexported fields
}

Future is a type that represents a value that will be available in the future. It is heavily inspired by Java's Future interface. It is used to represent the result of an asynchronous operation and a way to early return from a function.

The creation and completion of the future is done internally, so the user is not expected to create it manually. The user is responsible for obtaining the value from the future. There are two ways to do that: 1. By calling Get() method. This method will block until the value is available. It returns either the pointer to the value or an error. In pippin the error means that the pipeline was interrupted before it could complete that's why the value is not available. 2. By calling GetWithTimeout(timeout time.Duration) method. This method will block until the value is available or the timeout is reached.

The recommended way to obtain the value is by calling GetWithTimeout() method, as otherwise the execution might be blocked forever.

It is possible to manually check whether the future is done or not by calling IsDone() method. This method return a boolean value indicating whether the future is done or not. It is not blocking.

Please, note that since it's the async operation, the value might not be available immediately.

func NewFuture

func NewFuture[T any]() Future[T]

NewFuture creates a new future.

func (*Future[T]) Complete

func (f *Future[T]) Complete(value T)

Complete completes the future with the provided value.

func (*Future[T]) Fail

func (f *Future[T]) Fail(err error)

Fail completes the future with the provided error.

func (*Future[T]) Get

func (f *Future[T]) Get() (*T, error)

Get returns the value from the future. It blocks until the value is available. It returns either the pointer to the value or an error. The error means that the pipeline was interrupted before it could complete that's why the value is not available.

Use it with caution as it might block the execution forever. As an alternative consider using GetWithTimeout() method.

func (*Future[T]) GetWithTimeout

func (f *Future[T]) GetWithTimeout(timeout time.Duration) (*T, error)

GetWithTimeout returns the value from the future. It blocks until the value is available or the timeout is reached. It returns either the pointer to the value or an error. The error means that the pipeline was interrupted before it could complete that's why the value is not available.

This is the recommended way to obtain the value from the future.

func (*Future[T]) IsDone

func (f *Future[T]) IsDone() bool

IsDone returns a boolean value indicating whether the future is done or not. It is not blocking. Due to the asynchronous nature of the future, it is possible that the value is not available / not up-to-date immediately.

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

type Tuple

type Tuple[A, B any] struct {
	First  A
	Second B
}

type Void

type Void struct{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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