Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IOResult ¶
IOResult represents a synchronous computation that may fail with an error. It's an alias for ioresult.IOResult[T].
func WithContext ¶
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
Click to show internal directories.
Click to hide internal directories.