Documentation ¶
Overview ¶
Package gcancel provides a converter between gio.Cancellable and context.Context.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewCancellableContext ¶
NewCancellableContext creates a new context.Context from the given *GCancellable. If the pointer is nil, then context.Background() is used.
func WithCancel ¶
WithCancel behaves similarly to context.WithCancel, except the created context is of type Cancellable. This is useful if the user wants to reuse the same Cancellable instance for multiple calls.
This function costs a goroutine to do this unless the given context is previously created with WithCancel, is otherwise a Cancellable instance, or is an instance from context.Background() or context.TODO(), but it should be fairly cheap otherwise.
Types ¶
type Cancellable ¶
Cancellable is a wrapper around the GCancellable object. It satisfies the context.Context interface.
func GCancellableFromContext ¶
func GCancellableFromContext(ctx context.Context) *Cancellable
CancellableFromContext gets the underlying Cancellable instance from the given context. If ctx does not contain the Cancellable instance, then a context with a nil Object field is returned. It is mostly for internal use; users should use WithCancel instead.
func (*Cancellable) Cancel ¶
func (c *Cancellable) Cancel()
Cancel will set cancellable to cancelled. It is the same as calling the cancel callback given after context creation.
func (*Cancellable) Deadline ¶
func (c *Cancellable) Deadline() (time.Time, bool)
Deadline returns the deadline of the parent context.
func (*Cancellable) Done ¶
func (c *Cancellable) Done() <-chan struct{}
Done returns the channel that's closed once the cancellable is cancelled.
func (*Cancellable) Err ¶
func (c *Cancellable) Err() error
Err returns context.Canceled if the cancellable is already cancelled, otherwise nil is returned.
func (*Cancellable) IsCancelled ¶
func (c *Cancellable) IsCancelled() bool
IsCancelled checks if a cancellable job has been cancelled.
func (*Cancellable) Value ¶
func (c *Cancellable) Value(key interface{}) interface{}
Value returns the values of the parent context.