fstctx

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0, BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package fstctx provides alternatives to context.WithTimeout and context.WithDeadline. At the time of writing, TinyGo does not support the runtime methods needed to support those time based operations.

All packages in `x`, including package fstctx, should be considered temporary, experimental, and unstable.

Deprecated: Use the standard library `context` package instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithDeadline

func WithDeadline(parent context.Context, d time.Time) (context.Context, context.CancelFunc)

WithDeadline returns a copy of the parent context which will be cancelled when the deadline arrives. Unlike context.WithDeadline the deadline will not be adjusted, and it will not return the context.DeadlineExceeded error. Canceling before the deadline will not clean up the spawned goroutine however the goroutine will become a no-op. It is possible for pauses in Wasm execution to cause the cancellation to happen after the deadline. This should not be relied on for applications where a precise deadline is required.

Canceling this context releases resources associated with it, so code should call cancel as soon as the operations running in this Context complete.

func WithTimeout

func WithTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)

WithTimeout returns a copy of the parent context which will be cancelled after the provided timeout. Unlike context.WithTimeout the deadline will not be adjusted, and it will not return the context.DeadlineExceeded error. Canceling before the timeout will not clean up the spawned goroutine however the goroutine will become a no-op. It is possible for pauses in Wasm execution to cause the timeout to be delayed. This should not be relied on for applications where a precise timout is required.

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 := fstctx.WithTimeout(ctx, 100*time.Millisecond)
	defer cancel()  // releases resources if slowOperation completes before timeout elapses
	return slowOperation(ctx)
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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