chain

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const CapSize = 10

Variables

This section is empty.

Functions

func RegisterHandler

func RegisterHandler(catalog string, h Handler)

Types

type Callback

type Callback struct {
	Func  CallbackFunc
	Async bool
}

func (*Callback) Fail

func (cb *Callback) Fail(err error, args ...interface{})

func (*Callback) Invoke

func (cb *Callback) Invoke(r Result)

func (*Callback) Success

func (cb *Callback) Success(args ...interface{})

type CallbackFunc

type CallbackFunc func(r Result)

type Chain

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

func NewChain

func NewChain(name string, handlers []Handler) (ch Chain)

func (*Chain) Init

func (c *Chain) Init(chainName string, hs []Handler)

func (*Chain) Name

func (c *Chain) Name() string

func (*Chain) Next

func (c *Chain) Next(i *Invocation)

type Handler

type Handler interface {
	Handle(i *Invocation)
}

func Handlers

func Handlers(catalog string) []Handler

type Invocation

type Invocation struct {
	Callback
	// contains filtered or unexported fields
}

func NewInvocation

func NewInvocation(ctx context.Context, ch Chain) (inv Invocation)

func (*Invocation) Context

func (i *Invocation) Context() context.Context

func (*Invocation) Init

func (i *Invocation) Init(ctx context.Context, ch Chain)

func (*Invocation) Invoke

func (i *Invocation) Invoke(f CallbackFunc)

func (*Invocation) Next

func (i *Invocation) Next(opts ...InvocationOption)

Next is the method to go next step in handler chain WithFunc and WithAsyncFunc options can add customize callbacks in chain and the callbacks seq like below i.Success/Fail() -> CB1 ---> CB3 ----------> END goroutine 0

\-> CB2(async) \                  goroutine 1
                \-> CB4(async)    goroutine 1 or 2

func (*Invocation) WithContext

func (i *Invocation) WithContext(key string, val interface{}) *Invocation

type InvocationOp

type InvocationOp struct {
	Func  CallbackFunc
	Async bool
}

type InvocationOption

type InvocationOption func(op InvocationOp) InvocationOp

func WithAsyncFunc

func WithAsyncFunc(f func(r Result)) InvocationOption

func WithFunc

func WithFunc(f func(r Result)) InvocationOption

type Result

type Result struct {
	OK   bool
	Err  error
	Args []interface{}
}

func (Result) String

func (r Result) String() string

Jump to

Keyboard shortcuts

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