lisette-stdlib 0.1.16

Little language inspired by Rust that compiles to Go
Documentation
// Generated by Lisette bindgen
// Source: context (Go stdlib)
// Go: 1.25.5
// Lisette: 0.1.14

import "go:time"

/// AfterFunc arranges to call f in its own goroutine after ctx is canceled.
/// If ctx is already canceled, AfterFunc calls f immediately in its own goroutine.
/// 
/// Multiple calls to AfterFunc on a context operate independently;
/// one does not replace another.
/// 
/// Calling the returned stop function stops the association of ctx with f.
/// It returns true if the call stopped f from being run.
/// If stop returns false,
/// either the context is canceled and f has been started in its own goroutine;
/// or f was already stopped.
/// The stop function does not wait for f to complete before returning.
/// If the caller needs to know whether f is completed,
/// it must coordinate with f explicitly.
/// 
/// If ctx has a "AfterFunc(func()) func() bool" method,
/// AfterFunc will use it to schedule the call.
pub fn AfterFunc(ctx: Context, f: fn() -> ()) -> fn() -> bool

pub fn Background() -> Context

/// Cause returns a non-nil error explaining why c was canceled.
/// The first cancellation of c or one of its parents sets the cause.
/// If that cancellation happened via a call to CancelCauseFunc(err),
/// then [Cause] returns err.
/// Otherwise Cause(c) returns the same value as c.Err().
/// Cause returns nil if c has not been canceled yet.
pub fn Cause(c: Context) -> Option<error>

pub fn TODO() -> Context

/// WithCancel returns a derived context that points to the parent context
/// but has a new Done channel. The returned context's Done channel is closed
/// when the returned cancel function is called or when the parent context's
/// Done channel is closed, whichever happens first.
/// 
/// Canceling this context releases resources associated with it, so code should
/// call cancel as soon as the operations running in this [Context] complete.
pub fn WithCancel(parent: Context) -> (Context, CancelFunc)

/// WithCancelCause behaves like [WithCancel] but returns a [CancelCauseFunc] instead of a [CancelFunc].
/// Calling cancel with a non-nil error (the "cause") records that error in ctx;
/// it can then be retrieved using Cause(ctx).
/// Calling cancel with nil sets the cause to Canceled.
/// 
/// Example use:
/// 
/// 	ctx, cancel := context.WithCancelCause(parent)
/// 	cancel(myError)
/// 	ctx.Err() // returns context.Canceled
/// 	context.Cause(ctx) // returns myError
pub fn WithCancelCause(parent: Context) -> (Context, CancelCauseFunc)

/// WithDeadline returns a derived context that points to the parent context
/// but has the deadline adjusted to be no later than d. If the parent's
/// deadline is already earlier than d, WithDeadline(parent, d) is semantically
/// equivalent to parent. The returned [Context.Done] channel is closed when
/// the deadline expires, when the returned cancel function is called,
/// or when the parent context's Done channel is closed, whichever happens first.
/// 
/// Canceling this context releases resources associated with it, so code should
/// call cancel as soon as the operations running in this [Context] complete.
pub fn WithDeadline(parent: Context, d: time.Time) -> (Context, CancelFunc)

/// WithDeadlineCause behaves like [WithDeadline] but also sets the cause of the
/// returned Context when the deadline is exceeded. The returned [CancelFunc] does
/// not set the cause.
pub fn WithDeadlineCause(parent: Context, d: time.Time, cause: error) -> (Context, CancelFunc)

/// WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
/// 
/// Canceling this context releases resources associated with it, so code should
/// call cancel as soon as the operations running in this [Context] complete:
/// 
/// 	func slowOperationWithTimeout(ctx context.Context) (Result, error) {
/// 		ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
/// 		defer cancel()  // releases resources if slowOperation completes before timeout elapses
/// 		return slowOperation(ctx)
/// 	}
pub fn WithTimeout(parent: Context, timeout: time.Duration) -> (Context, CancelFunc)

/// WithTimeoutCause behaves like [WithTimeout] but also sets the cause of the
/// returned Context when the timeout expires. The returned [CancelFunc] does
/// not set the cause.
pub fn WithTimeoutCause(parent: Context, timeout: time.Duration, cause: error) -> (Context, CancelFunc)

pub fn WithValue(parent: Context, key: Unknown, val: Unknown) -> Context

pub fn WithoutCancel(parent: Context) -> Context

/// A CancelCauseFunc behaves like a [CancelFunc] but additionally sets the cancellation cause.
/// This cause can be retrieved by calling [Cause] on the canceled Context or on
/// any of its derived Contexts.
/// 
/// If the context has already been canceled, CancelCauseFunc does not set the cause.
/// For example, if childContext is derived from parentContext:
///   - if parentContext is canceled with cause1 before childContext is canceled with cause2,
///     then Cause(parentContext) == Cause(childContext) == cause1
///   - if childContext is canceled with cause2 before parentContext is canceled with cause1,
///     then Cause(parentContext) == cause1 and Cause(childContext) == cause2
pub type CancelCauseFunc = fn(error) -> ()

/// A CancelFunc tells an operation to abandon its work.
/// A CancelFunc does not wait for the work to stop.
/// A CancelFunc may be called by multiple goroutines simultaneously.
/// After the first call, subsequent calls to a CancelFunc do nothing.
pub type CancelFunc = fn() -> ()

/// A Context carries a deadline, a cancellation signal, and other values across
/// API boundaries.
/// 
/// Context's methods may be called by multiple goroutines simultaneously.
pub interface Context {
  fn Deadline() -> Option<time.Time>
  fn Done() -> Receiver<()>
  fn Err() -> Option<error>
  fn Value(key: Unknown) -> Unknown
}

/// Canceled is the error returned by [Context.Err] when the context is canceled
/// for some reason other than its deadline passing.
pub var Canceled: error

/// DeadlineExceeded is the error returned by [Context.Err] when the context is canceled
/// due to its deadline passing.
pub var DeadlineExceeded: error