synx

package module
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2025 License: Apache-2.0, MIT Imports: 5 Imported by: 3

README

Synx Go Reference

Synx is enhanced version of standard sync package.

License

Synx is primarily distributed under the terms of both the MIT license and Apache License (Version 2.0).

See LICENSE-APACHE and/or LICENSE-MIT for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidTimeout         = errors.New("timeout is zero or negative")
	ErrContextWithoutDeadline = errors.New("context has no deadline")
)

Functions

func CallWithContext added in v0.13.0

func CallWithContext(ctx context.Context, fn func(context.Context) error) error

func CallWithTimeout added in v0.13.0

func CallWithTimeout(timeout time.Duration, fn func(context.Context) error) error

func Graceful added in v0.10.0

func Graceful(ctx context.Context, fn func(context.Context) error) (err error)

Graceful runs given function with given context and catch panics, which return as error.

Types

type CtxGroup added in v0.10.0

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

A CtxGroup is a collection of goroutines working on subtasks that are part of the same overall task.

func NewCtxGroup added in v0.10.0

func NewCtxGroup(ctx context.Context) *CtxGroup

NewCtxGroup returns a new CtxGroup with an derived Context from ctx.

func (*CtxGroup) Go added in v0.10.0

func (g *CtxGroup) Go(f func(ctx context.Context) error)

Go calls the given function in a new goroutine.

func (*CtxGroup) Wait added in v0.10.0

func (g *CtxGroup) Wait() error

Wait blocks until all function calls from the Go method have returned.

type ErrGroup added in v0.7.0

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

A ErrGroup is a collection of goroutines working on subtasks that are part of the same overall task.

A zero ErrGroup is valid and does not cancel on error.

func NewErrGroup added in v0.7.0

func NewErrGroup(ctx context.Context) *ErrGroup

NewErrGroup returns a new Group with an derived Context from ctx.

The derived Context is canceled the first time a function passed to Go returns a non-nil error or the first time Wait returns, whichever occurs first.

func (*ErrGroup) Go added in v0.7.0

func (g *ErrGroup) Go(f func(ctx context.Context) error)

Go calls the given function in a new goroutine.

The first call to return a non-nil error cancels the group; its error will be returned by Wait.

func (*ErrGroup) Wait added in v0.7.0

func (g *ErrGroup) Wait() error

Wait blocks until all function calls from the Go method have returned, then returns the first non-nil error (if any) from them.

Jump to

Keyboard shortcuts

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