g

package
v0.0.0-...-b044761 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package g is a goroutine life cycle management package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type G

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

G is a goroutine

func Go

func Go(f func() error) *G

Go runs a given f concurrently and returns a coresponding goroutine instance.

func (*G) Cancel

func (g *G) Cancel() *G

Cancel cancels the goroutine. Note that the goroutine does not get stopped and a good practice is to use Cancel with WithUndo function:

g := g.Go(func() error { ... }).WithUndo(func() { ... })
...
err := g.Cancel().Wait().Err()
if err != nil { ... }

Then the settled undo function will be executed after the cancellation.

func (*G) Err

func (g *G) Err() error

Err reports if the goroutine returns error, This call will wait until the goroutine terminates.

func (*G) Wait

func (g *G) Wait() *G

Wait wait until the goroutine terminates.

func (*G) WithUndo

func (g *G) WithUndo(undo func()) *G

WithUndo sets up a function that can be executed if a goroutine is canceled.

Jump to

Keyboard shortcuts

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