Help us shape the future of Go! Take the 2026 Go Developer Survey

ioresult

package
v2.3.21 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IOResult

type IOResult[T any] = ioresult.IOResult[T]

IOResult represents a synchronous computation that may fail with an error. It's an alias for ioresult.IOResult[T].

func WithContext

func WithContext[A any](ctx context.Context, ma IOResult[A]) IOResult[A]

WithContext wraps an IOResult and performs a context check for cancellation before executing. This ensures that if the context is already cancelled, the computation short-circuits immediately without executing the wrapped computation.

This is useful for adding cancellation awareness to computations that might not check the context themselves.

Type Parameters:

  • A: The type of the success value

Parameters:

  • ctx: The context to check for cancellation
  • ma: The IOResult to wrap with context checking

Returns:

  • An IOResult that checks for cancellation before executing

Example:

computation := func() Result[string] {
    // Long-running operation
    return result.Of("done")
}

ctx, cancel := context.WithCancel(t.Context())
cancel() // Cancel immediately

wrapped := WithContext(ctx, computation)
result := wrapped() // Returns Left with context.Canceled error

type Result

type Result[T any] = result.Result[T]

Result represents a computation that may fail with an error. It's an alias for result.Result[T].

Jump to

Keyboard shortcuts

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