async

package module
v0.0.0-...-44157fd Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2017 License: BSD-3-Clause Imports: 5 Imported by: 0

README

Async

Build Status codecov Go Report Card GoDoc

Provides a safe way to execute fns's functions asynchronously, recovering them in case of panic. It also provides an error stack aiming to facilitate fail causes discovery.

Usage

func InsertAsynchronously(ctx context.Context) error {
	transaction := db.Transaction().Begin()

	err := async.Run(ctx,
		func(_ context.Context) error {
			_, err := transaction.Exec(`
				INSERT INTO foo (bar)
				VALUES ('Hello')
			`)

			return err
		},

		func(_ context.Context) error {
			_, err := transaction.Exec(`
				INSERT INTO foo (bar)
				VALUES ('world')
			`)

			return err
		},

		func(_ context.Context) error {
			_, err := transaction.Exec(`
				INSERT INTO foo (bar)
				VALUES ('asynchronously!')
			`)

			return err
		},
	)

	if err != nil {
		e := transaction.Rollback()
		log.IfError(e)
		return err
	}

	return transaction.Commit()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(parent context.Context, fns ...func(ctx context.Context) error) error

Run provides a safe way to execute fns's functions asynchronously, recovering if they panic and provides all error stack aiming to facilitate fail causes discovery

Types

This section is empty.

Jump to

Keyboard shortcuts

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