step

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Generic Concurrency primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func After

func After[T any, F func(T)](s *Step[T], f F)

Run a computation after a Step has succeeded.

func Zero

func Zero[T any]() (zero T)

Zero returns the zero value for a type.

Types

type Step

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

Step represents a computation that may produce a value. This is equivalent to a `Future` in other languages.

func New

func New[T any, F func() (T, bool)](ctx context.Context, f F) *Step[T]

Create a new Step not predicated on any other step. `f` is the computation that the step represents. The second return value indicates if the computation succeeded.

func Then

func Then[T, U any, F func(T) (U, bool)](s *Step[T], f F) *Step[U]

Chain a step (if it succeeded) into another step.

func (*Step[T]) GetResult

func (s *Step[T]) GetResult() (T, bool)

Block on retrieving the computed result. If the computation is canceled, Zero[T](), false is returned.

func (*Step[T]) TryGetResult

func (s *Step[T]) TryGetResult() (T, bool)

A non-blocking attempt to retrieve the value produced by the Step. The bool is true if a computed value is returned. False indicates that the attempt failed.

Jump to

Keyboard shortcuts

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