deferred

package
v0.0.0-...-8b02fee Latest Latest
Warning

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

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

Documentation

Overview

Package deferred provides tools for deferring actions to be run at a later time. These can be thought of as an extension and generalization of the language's built-in defer statement.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue []func()

A Queue is a queue of actions to run at some later time. The actions will be run in the order they are added with Defer. Note that this is different from the language's built-in defer statement, which runs actions in reverse order (future versions of this package may add a Stack type to support those semantics).

The zero value is an empty queue.

The advantage of this vs. built-in defer is that it needn't be tied to the scope of a single function; for example, you can write code like:

q := &Queue{} defer q.Run() f(q) // pass the queue to a subroutine, which may queue

// up actions to be run after *this* function returns.

func (*Queue) Defer

func (q *Queue) Defer(f func())

Defer adds f to the list of functions to call when Run() is invoked.

func (*Queue) Run

func (q *Queue) Run()

Run runs all deferred actions, in the order they were added.

Jump to

Keyboard shortcuts

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