stdlib

package
v0.0.0-...-1837d0f Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2022 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSuchApplication = errors.New("no such application")
)

Functions

func Catch

func Catch(f func())

func Close

func Close()

func Go

func Go(run GoRun, onRet OnReturn)

func Post

func Post(ctx context.Context, receiver def.ActorID, message def.Message)

func RegisterActorCreator

func RegisterActorCreator(actorType def.ActorType, creator ActorCreator) bool

func RegisterApplication

func RegisterApplication(name string, creator def.NewApplication)

func StartApplication

func StartApplication(v *viper.Viper, name string) error

func StartApplications

func StartApplications(v *viper.Viper, apps []string) error

func Wait

func Wait()

Types

type Actor

type Actor interface {
	Initialize(v *viper.Viper) error // will be called by supervisor
	Terminate()                      // will be called in actor's goroutine

	DefaultImplement
}

func NewActor

func NewActor(actorType def.ActorType, id def.ActorID) Actor

type ActorCreator

type ActorCreator func() Actor

type DefaultImplement

type DefaultImplement interface {
	ID() def.ActorID
	Type() def.ActorType

	MessageQueue() def.MessageQueue

	Handler
	Receiver
	// contains filtered or unexported methods
}

type ExitChan

type ExitChan chan int

type GoRun

type GoRun func(ExitChan) (def.Message, error)

type Handler

type Handler interface {
	Handle(ctx context.Context, message def.Message, args ...interface{}) error // will be called in actor's goroutine
}

type Manager

type Manager struct {
	ExitChan
	// contains filtered or unexported fields
}

func NewManager

func NewManager() *Manager

func (*Manager) Close

func (m *Manager) Close()

func (*Manager) Get

func (m *Manager) Get(id def.ActorID) Actor

func (*Manager) Go

func (m *Manager) Go(run GoRun, onRet OnReturn)

func (*Manager) NewActor

func (m *Manager) NewActor(actorType def.ActorType, id def.ActorID) Actor

func (*Manager) Post

func (m *Manager) Post(ctx context.Context, receiver def.ActorID, message def.Message)

func (*Manager) Wait

func (m *Manager) Wait()

type OnReturn

type OnReturn func(def.Message, error)

type Receiver

type Receiver interface {
	Post(ctx context.Context, message def.Message) // post message to actor's message queue, must thread safe
}

type SimpleActor

type SimpleActor struct {
	sc.SimpleState
	// contains filtered or unexported fields
}

func (*SimpleActor) Handle

func (a *SimpleActor) Handle(ctx context.Context, message def.Message, args ...interface{}) error

func (*SimpleActor) ID

func (a *SimpleActor) ID() def.ActorID

func (*SimpleActor) Initialize

func (a *SimpleActor) Initialize() error

must be called by outer Initialize and ignore error

func (*SimpleActor) MessageQueue

func (a *SimpleActor) MessageQueue() def.MessageQueue

func (*SimpleActor) Post

func (a *SimpleActor) Post(ctx context.Context, message def.Message)

no any check for performance Post will lock if the mq has not been initial

func (*SimpleActor) Terminate

func (a *SimpleActor) Terminate()

func (*SimpleActor) Type

func (a *SimpleActor) Type() def.ActorType

type Supervisor

type Supervisor struct {
}

func NewSupervisor

func NewSupervisor() (*Supervisor, error)

func (*Supervisor) Handle

func (sup *Supervisor) Handle(message def.Message) def.Message

func (*Supervisor) HandleActor

func (sup *Supervisor) HandleActor(actor def.ActorID, message def.Message)

func (*Supervisor) Initialize

func (sup *Supervisor) Initialize() error

func (*Supervisor) Start

func (sup *Supervisor) Start(v *viper.Viper, actorType def.ActorType, actorID def.ActorID) (Actor, error)

type TwoWayMap

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

func NewTwoWayMap

func NewTwoWayMap(concurrent bool) *TwoWayMap

func (*TwoWayMap) Delete

func (m *TwoWayMap) Delete(key interface{})

Delete deletes the value for a key.

func (*TwoWayMap) Load

func (m *TwoWayMap) Load(key interface{}) (value interface{}, ok bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*TwoWayMap) LoadAndDelete

func (m *TwoWayMap) LoadAndDelete(key interface{}) (value interface{}, loaded bool)

LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.

func (*TwoWayMap) LoadOrStore

func (m *TwoWayMap) LoadOrStore(key, value interface{}) (actual interface{}, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*TwoWayMap) Range

func (m *TwoWayMap) Range(f func(key, value interface{}) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently, Range may reflect any mapping for that key from any point during the Range call.

Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.

func (*TwoWayMap) Store

func (m *TwoWayMap) Store(key, value interface{})

Store sets the value for a key.

Jump to

Keyboard shortcuts

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