Skip to content

Import path: gitlab.soludian.com/soludian/fountain/libs/base/syncs

syncs

go
import "gitlab.soludian.com/soludian/fountain/libs/base/syncs"

Package syncs provides synchronization primitives util functions.

Index

func Go

go
func Go(f func() error) error

Go is a basic promise implementation: it wraps calls a function in a goroutine and returns a channel which will later return the function's return value.

func SignalHandler

go
func SignalHandler(ctx context.Context, signals ...os.Signal) (execute func() error, interrupt func(error))

SignalHandler returns an actor, i.e. an execute and interrupt func, that terminates with SignalError when the process receives one of the provided signals, or the parent context is canceled.

from https://github.com/oklog/run/blob/master/actors.go

func WaitCloseSignals

go
func WaitCloseSignals(onClose func(sig os.Signal))

WaitCloseSignals for some huang program.

Usage:

... do something. eg: start a http server

	syncs.WaitCloseSignals(func(sig os.Signal) {
 ... do something
	})

type SignalError

SignalError is returned by the signal handler's execute function when it terminates due to a received signal.

go
type SignalError struct {
    Signal os.Signal
}

func (SignalError) Error

go
func (e SignalError) Error() string

Error implements the error interface.

Generated by gomarkdoc