thunk

package
v0.0.0-...-8b02fee Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: Apache-2.0 Imports: 1 Imported by: 1

Documentation

Overview

Package thunk provides "thunks" (type T), which are wrappers around lazy or concurrent computations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Thunk

type Thunk[A any] struct {
	// contains filtered or unexported fields
}

A Thunk[A] wraps a value A which may not be available yet; goroutines may get the value by calling Force.

func Go

func Go[A any](f func() A) *Thunk[A]

Go is like Lazy, except that f() is invoked immediately in a separate goroutine. Calls to Force will block until f() returns.

func Lazy

func Lazy[A any](f func() A) *Thunk[A]

Lazy returns a new Thunk which, when forced, will return the value returned by f(). f() will be invoked lazily, i.e. not until Force() is called for the first time.

func Promise

func Promise[A any]() (t *Thunk[A], fulfill func(A))

Promise returns a pair of a Thunk and a function fulfill to supply the value of the Thunk; calls to t.Force() will block until fulfill has been invoked, at which point they will return the value passed to fulfill. Fulfill must not be called more than once.

func Ready

func Ready[A any](value A) *Thunk[A]

Ready returns a new Thunk which is already ready; when forced it will return value immediately.

func (*Thunk[A]) Force

func (t *Thunk[A]) Force() A

Force waits for the result of the Thunk to be available and returns it.

Jump to

Keyboard shortcuts

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