synx

package module
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: Apache-2.0, MIT Imports: 6 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.

type WorkPool added in v0.14.0

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

A WorkPool manages a pool of goroutines with a maximum concurrency limit. It uses semaphore to control the number of concurrent operations.

func NewWorkPool added in v0.14.0

func NewWorkPool(ctx context.Context, maxWorkers int64) *WorkPool

NewWorkPool creates a new WorkPool with the specified maximum concurrency. maxWorkers defines the maximum number of concurrent goroutines that can run.

func (*WorkPool) Go added in v0.14.0

func (p *WorkPool) Go(f func(ctx context.Context) error) error

Go submits a function to be executed in the work pool. It will block if the maximum number of workers is already running. The function will be executed when a worker becomes available.

func (*WorkPool) MaxWorkers added in v0.14.0

func (p *WorkPool) MaxWorkers() int64

MaxWorkers returns the maximum number of concurrent workers.

func (*WorkPool) TryGo added in v0.14.0

func (p *WorkPool) TryGo(f func(ctx context.Context) error) bool

TryGo attempts to submit a function to be executed in the work pool. It returns false if the maximum number of workers is already running, true if the function was successfully submitted.

func (*WorkPool) Wait added in v0.14.0

func (p *WorkPool) Wait() error

Wait blocks until all submitted work has completed and returns any errors that occurred during execution.

Jump to

Keyboard shortcuts

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