defergroup

package
v0.4.31 Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: GPL-3.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeferGroup

type DeferGroup struct {
	// contains filtered or unexported fields
}

Just like "defer", but can be canceled. Useful in constructor functions when there are multiple resources need to be acquired, but that can fail to be allocated itself.

Examples:

 dg := DeferGroup{}
	defer dg.Exec()

	resource, err := Allocate()
	if err != nil {
		return err
	}
	dg.Defer(func() { resource.Close() })

	// More allocations.

	dg.CancelExec() // Everything is OK, no cleanup required.
	return nil

func (*DeferGroup) CancelExec

func (m *DeferGroup) CancelExec()

func (*DeferGroup) Defer

func (m *DeferGroup) Defer(fn func())

func (*DeferGroup) Exec

func (m *DeferGroup) Exec()

Jump to

Keyboard shortcuts

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