Documentation ¶
Overview ¶
Example (TraceFromVar) ¶
var tr TracerFunc = func(events ...Term) { fmt.Println(events[0]) } tr.Event("some event")
Output: some event
Example (TraceFunc) ¶
Example tests
tr := traceToTracerFunc() tr.Event("some event")
Output: traceToTracerFunc called
Example (TraceInterfaceImplementation) ¶
obj := new(someTracer) tr := TracerFunc(obj.Trace) tr.Event("some event")
Output: tracer with receiver
Index ¶
- Constants
- func CompareRefs(a, b Ref) int
- func IsAlreadyRegError(err error) bool
- func IsChannelFullError(err error) bool
- func IsExitNormalError(e error) bool
- func IsNameEmptyError(err error) bool
- func IsNilPidError(err error) bool
- func IsNoProcError(err error) bool
- func IsNotRegError(err error) bool
- func IsPrefixEmptyError(err error) bool
- func TimerCancel(tref Term) error
- func TimerServerStart() (err error)
- func TraceCall(t Tracer, pid *Pid, tag string, arg Term) *time.Time
- func TraceCallResult(t Tracer, pid *Pid, start *time.Time, tag string, arg, result Term)
- type AsyncReq
- type Call
- type CallResult
- type Env
- func (e *Env) GenServerStart(gs GenServer, args ...Term) (*Pid, error)
- func (e *Env) GenServerStartOpts(gs GenServer, opts *SpawnOpts, args ...Term) (*Pid, error)
- func (e *Env) MakeRef() Ref
- func (e *Env) Spawn(f GenProcFunc, args ...Term) (*Pid, error)
- func (e *Env) SpawnObj(gp GenProc, opts *SpawnOpts, args ...Term) (*Pid, error)
- func (e *Env) SpawnWithOpts(f GenProcFunc, opts *SpawnOpts, args ...Term) (*Pid, error)
- func (e *Env) Whereare(prefix string) (RegMap, error)
- func (e *Env) Whereis(name Term) (*Pid, error)
- func (e *Env) WhereisPrefix(prefix string, name Term) (*Pid, error)
- type ExitPidReq
- type From
- type GenProc
- type GenProcFunc
- type GenProcSys
- func (gps *GenProcSys) DemonitorProcessPid(ref Ref)
- func (gps *GenProcSys) GenProcLoop(args ...Term) error
- func (gps *GenProcSys) HandleSysMsg(msg Term) (err error)
- func (gps *GenProcSys) InitAck() error
- func (gps *GenProcSys) InitPrepare()
- func (gps *GenProcSys) Link(pid *Pid)
- func (gps *GenProcSys) MonitorProcessPid(pid *Pid) Ref
- func (gps *GenProcSys) Run(gp GenProc, opts *SpawnOpts, args ...Term)
- func (gps *GenProcSys) Self() *Pid
- func (gps *GenProcSys) SetTracer(t Tracer)
- func (gps *GenProcSys) SetTrapExit(flag bool)
- func (gps *GenProcSys) Tracer() Tracer
- func (gps *GenProcSys) TrapExit() bool
- func (gps *GenProcSys) Unlink(pid *Pid)
- type GenServer
- type GenServerSys
- func (gs *GenServerSys) CallReply(reply Term) Term
- func (gs *GenServerSys) CallReplyOk() Term
- func (gs *GenServerSys) CallReplyTimeout(reply Term, timeout time.Duration) Term
- func (gs *GenServerSys) CallStop(reason string, reply Term) Term
- func (gs *GenServerSys) GenProcLoop(args ...Term) (err error)
- func (gs *GenServerSys) HandleCall(req Term, from From) Term
- func (gs *GenServerSys) HandleCast(req Term) Term
- func (gs *GenServerSys) HandleInfo(req Term) Term
- func (gs *GenServerSys) Init(args ...Term) Term
- func (gs *GenServerSys) InitAck() error
- func (gs *GenServerSys) InitOk() Term
- func (gs *GenServerSys) InitPrepare()
- func (gs *GenServerSys) InitTimeout(timeout time.Duration) Term
- func (gs *GenServerSys) NoReply() Term
- func (gs *GenServerSys) NoReplyTimeout(timeout time.Duration) Term
- func (gs *GenServerSys) Reply(from From, data Term)
- func (gs *GenServerSys) Stop(reason string) Term
- func (gs *GenServerSys) Terminate(reason string)
- type GsReply
- type GsTimeout
- type Gts
- type GtsForEach
- type GtsIterator
- type GtsKeysComparator
- type LinkPidReq
- type MonitorDownReq
- type Pid
- func GenServerStart(gs GenServer, args ...Term) (*Pid, error)
- func GenServerStartOpts(gs GenServer, opts *SpawnOpts, args ...Term) (*Pid, error)
- func Spawn(f GenProcFunc, args ...Term) (*Pid, error)
- func SpawnObj(gp GenProc, opts *SpawnOpts, args ...Term) (*Pid, error)
- func SpawnWithOpts(f GenProcFunc, opts *SpawnOpts, args ...Term) (*Pid, error)
- func Whereis(name Term) (*Pid, error)
- func WhereisPrefix(prefix string, name Term) (*Pid, error)
- func (pid *Pid) Alive() error
- func (pid *Pid) Call(data Term) (Term, error)
- func (pid *Pid) CallSys(data Term) (Term, error)
- func (pid *Pid) Cast(data Term) error
- func (pid *Pid) Equal(pid2 *Pid) bool
- func (pid *Pid) Exit(reason string) error
- func (pid *Pid) ExitReason(pidTo *Pid, reason string) error
- func (pid *Pid) GenServerStartLink(gs GenServer, opts *SpawnOpts, args ...Term) (*Pid, error)
- func (pid *Pid) GetSysChannel() <-chan Term
- func (pid *Pid) GetUsrChannel() <-chan Term
- func (pid *Pid) ID() uint64
- func (pid *Pid) ProcessLinks() ([]*Pid, error)
- func (pid *Pid) Register(name Term) error
- func (pid *Pid) RegisterPrefix(prefix string, name Term) error
- func (pid *Pid) RunAfter(f RunTimerFunc, timeoutMs uint32) *Timer
- func (pid *Pid) Send(data Term) error
- func (pid *Pid) SendAfter(data Term, timeoutMs uint32) *Timer
- func (pid *Pid) SendSys(data Term) error
- func (pidFrom *Pid) SpawnLink(f GenProcFunc, args ...Term) (*Pid, error)
- func (pidFrom *Pid) SpawnOptsLink(f GenProcFunc, opts *SpawnOpts, args ...Term) (*Pid, error)
- func (pid *Pid) Stop() (err error)
- func (pid *Pid) StopReason(reason string) (err error)
- func (pid *Pid) String() string
- func (pid *Pid) Unregister(name Term) error
- func (pid *Pid) UnregisterPrefix(prefix string, name Term) error
- type ProcessLinksReq
- type Ref
- type RegMap
- type RunTimerFunc
- type SpawnOpts
- func (op *SpawnOpts) WithLinkTo(pid *Pid) *SpawnOpts
- func (op *SpawnOpts) WithName(name string) *SpawnOpts
- func (op *SpawnOpts) WithPrefix(prefix string) *SpawnOpts
- func (op *SpawnOpts) WithSpawnOrLocate() *SpawnOpts
- func (op *SpawnOpts) WithSysChannelSize(size int) *SpawnOpts
- func (op *SpawnOpts) WithTracer(t Tracer) *SpawnOpts
- func (op *SpawnOpts) WithUsrChannelSize(size int) *SpawnOpts
- type StopPidReq
- type SyncReq
- type SysReq
- type Term
- type Timer
- type Tracer
- type TracerFunc
- type UnlinkPidReq
Examples ¶
Constants ¶
const ( NoProcError noProcError = 1 NilPidError nilPidError = 2 ChannelFullError chanFullError = 3 AlreadyRegError alreadyRegError = 5 NotRegError notRegError = 6 NameEmptyError nameEmptyError = 7 PrefixEmptyError prefixEmptyError = 8 NoProc string = "no_proc" )
Errors constants
const ( ExitNormal string = "normal" ExitKill string = "kill" ExitKilled string = "killed" )
Exit process reason constants
Variables ¶
This section is empty.
Functions ¶
func IsAlreadyRegError ¶
IsAlreadyRegError checks if error is an AlreadyRegError
func IsChannelFullError ¶
IsChannelFullError checks if error is a ChannelFullError
func IsExitNormalError ¶
IsExitNormalError checks if error is an ExitNormalError
func IsNameEmptyError ¶
IsNameEmptyError checks if error is a NameEmptyError
func IsNilPidError ¶
IsNilPidError checks if error is a NilPidError
func IsNoProcError ¶
IsNoProcError checks if error is of type of noProcError
func IsNotRegError ¶
IsNotRegError checks if error is a NotRegError
func IsPrefixEmptyError ¶
IsPrefixEmptyError checks if error is a PrefixEmptyError
Types ¶
type CallResult ¶
CallResult is a predefined tracer event for GenProc. Fired after call.
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env is environment for processes. Env used to group processes. Env has methods for process creation and registration.
func (*Env) GenServerStart ¶
GenServerStart start GenServer process in specified environment
func (*Env) GenServerStartOpts ¶
GenServerStartOpts start GenServer process in specified environment
with given options
func (*Env) Spawn ¶
func (e *Env) Spawn( f GenProcFunc, args ...Term) (*Pid, error)
Spawn makes new GenProc object and runs it's GenProcLoop
func (*Env) SpawnWithOpts ¶
SpawnWithOpts makes new GenProc object and runs it's GenProcLoop
type ExitPidReq ¶
ExitPidReq message sent to process when other linked process died or
explicitly by Exit or ExitReason
type GenProc ¶
type GenProc interface { // // Handle sys messages for process // HandleSysMsg(msg Term) error // // Process flag // SetTrapExit(flag bool) TrapExit() bool // // Returns pid of the process // Self() *Pid // // Runs f, transforms return value into ExitPidReq message // Run(gp GenProc, opts *SpawnOpts, args ...Term) GenProcLoop(args ...Term) error // // Waits ack from f // InitPrepare() InitAck() error // // Links // Link(*Pid) Unlink(*Pid) // // Monitors // MonitorProcessPid(*Pid) Ref DemonitorProcessPid(Ref) // // Tracer // SetTracer(Tracer) Tracer() Tracer // contains filtered or unexported methods }
GenProc interface
func NewGenProcSys ¶
func NewGenProcSys(f GenProcFunc) GenProc
NewGenProcSys creates GenProcSys object and returns it as GenProc interface
type GenProcFunc ¶
GenProcFunc is a type for loop function of the process
type GenProcSys ¶
type GenProcSys struct {
// contains filtered or unexported fields
}
GenProcSys is a default implementation of GenProc interface
func (*GenProcSys) DemonitorProcessPid ¶
func (gps *GenProcSys) DemonitorProcessPid(ref Ref)
DemonitorProcessPid removes the monitor for process identified by ref
func (*GenProcSys) GenProcLoop ¶
func (gps *GenProcSys) GenProcLoop(args ...Term) error
GenProcLoop implements process loop
func (*GenProcSys) HandleSysMsg ¶
func (gps *GenProcSys) HandleSysMsg(msg Term) (err error)
HandleSysMsg handles system messages for the process
func (*GenProcSys) InitAck ¶
func (gps *GenProcSys) InitAck() error
InitAck used for reply to calles the result of the process initialization
func (*GenProcSys) InitPrepare ¶
func (gps *GenProcSys) InitPrepare()
InitPrepare is empty for GenProc
func (*GenProcSys) MonitorProcessPid ¶
func (gps *GenProcSys) MonitorProcessPid(pid *Pid) Ref
MonitorProcessPid sets monitor for process identified by pid
func (*GenProcSys) Run ¶
func (gps *GenProcSys) Run(gp GenProc, opts *SpawnOpts, args ...Term)
Run starts process
func (*GenProcSys) SetTracer ¶
func (gps *GenProcSys) SetTracer(t Tracer)
SetTracer sets tracer for the process
func (*GenProcSys) SetTrapExit ¶
func (gps *GenProcSys) SetTrapExit(flag bool)
SetTrapExit sets trap_exit flag for the process
func (*GenProcSys) Tracer ¶
func (gps *GenProcSys) Tracer() Tracer
Tracer returns current tracer of the process
func (*GenProcSys) TrapExit ¶
func (gps *GenProcSys) TrapExit() bool
TrapExit returns trap_exit flag of the process
func (*GenProcSys) Unlink ¶
func (gps *GenProcSys) Unlink(pid *Pid)
Unlink removes the link from pid
type GenServer ¶
type GenServer interface { GenProc Init(args ...Term) Term HandleCall(req Term, from From) (result Term) HandleCast(req Term) (result Term) HandleInfo(req Term) (result Term) Terminate(reason string) // contains filtered or unexported methods }
GenServer is an interface for callbacks functions of the process
type GenServerSys ¶
type GenServerSys struct { GenProcSys // contains filtered or unexported fields }
GenServerSys is a default implementation of GenServer interface
func (*GenServerSys) CallReply ¶
func (gs *GenServerSys) CallReply(reply Term) Term
CallReply makes CallReply reply
func (*GenServerSys) CallReplyOk ¶
func (gs *GenServerSys) CallReplyOk() Term
CallReplyOk makes gsCallReplyOk reply
func (*GenServerSys) CallReplyTimeout ¶
func (gs *GenServerSys) CallReplyTimeout( reply Term, timeout time.Duration) Term
CallReplyTimeout makes CallReplyTimeout reply
func (*GenServerSys) CallStop ¶
func (gs *GenServerSys) CallStop(reason string, reply Term) Term
CallStop makes CallStop reply
func (*GenServerSys) GenProcLoop ¶
func (gs *GenServerSys) GenProcLoop(args ...Term) (err error)
GenProcLoop is a main gen_server loop function
func (*GenServerSys) HandleCall ¶
func (gs *GenServerSys) HandleCall(req Term, from From) Term
HandleCall handles incoming messages from `pid.Call(data)`
func (*GenServerSys) HandleCast ¶
func (gs *GenServerSys) HandleCast(req Term) Term
HandleCast handles incoming messages from `pid.Cast(data)`
func (*GenServerSys) HandleInfo ¶
func (gs *GenServerSys) HandleInfo(req Term) Term
HandleInfo handles timeouts and system messages
func (*GenServerSys) Init ¶
func (gs *GenServerSys) Init(args ...Term) Term
Init initializes process state using arbitrary arguments
func (*GenServerSys) InitAck ¶
func (gs *GenServerSys) InitAck() error
InitAck waits for result of process initialization
func (*GenServerSys) InitPrepare ¶
func (gs *GenServerSys) InitPrepare()
InitPrepare makes channel for InitAck
func (*GenServerSys) InitTimeout ¶
func (gs *GenServerSys) InitTimeout(timeout time.Duration) Term
InitTimeout makes InitTimeout reply
func (*GenServerSys) NoReplyTimeout ¶
func (gs *GenServerSys) NoReplyTimeout(timeout time.Duration) Term
NoReplyTimeout makes NoReplyTimeout reply
func (*GenServerSys) Reply ¶
func (gs *GenServerSys) Reply(from From, data Term)
Reply directly to caller
func (*GenServerSys) Terminate ¶
func (gs *GenServerSys) Terminate(reason string)
Terminate called when process died
type Gts ¶
type Gts interface { Insert(key Term, value Term) Delete(key Term) Lookup(key Term) Term Size() int DeleteAllObjects() Print() GtsIterator }
Gts is the interface to manipulate values in the table
func NewOrderedSet ¶
func NewOrderedSet() Gts
NewOrderedSet makes new ordered set With int keys comparator
func NewOrderedSetWith ¶
func NewOrderedSetWith(cmp GtsKeysComparator) Gts
NewOrderedSetWith makes new ordered set with specified keys compare function
type GtsForEach ¶
type GtsForEach func(a, b interface{}) bool
GtsForEach is an iterator function type to iterate over all keys in table
type GtsIterator ¶
type GtsIterator interface { First() (Term, Term, bool) Last() (Term, Term, bool) Next() (Term, Term, bool) Prev() (Term, Term, bool) ForEach(GtsForEach) }
GtsIterator is the interface that difines functions to iterater over the table
type GtsKeysComparator ¶
type GtsKeysComparator func(a, b interface{}) int
GtsKeysComparator is a function for ordered set to compare keys
type MonitorDownReq ¶
MonitorDownReq is a message sent when monitored process died
type Pid ¶
type Pid struct {
// contains filtered or unexported fields
}
Pid encapsulates process identificator and channels to communicate with process
func GenServerStart ¶
GenServerStart start GenServer process in default environment
func GenServerStartOpts ¶
GenServerStartOpts start GenServer process in default environment
with given options
func Spawn ¶
func Spawn( f GenProcFunc, args ...Term) (*Pid, error)
Spawn makes new GenProc object and runs it's GenProcLoop
func SpawnWithOpts ¶
func SpawnWithOpts( f GenProcFunc, opts *SpawnOpts, args ...Term) (*Pid, error)
SpawnWithOpts makes new GenProc object and runs it's GenProcLoop
func WhereisPrefix ¶
WhereisPrefix lookups process by prefix and name in default environment
func (*Pid) ExitReason ¶
ExitReason Sends async exit request to other process
func (*Pid) GenServerStartLink ¶
GenServerStartLink start GenServer process in default environment
and links it to called process
func (*Pid) GetSysChannel ¶
GetSysChannel returns sys channel
func (*Pid) GetUsrChannel ¶
GetUsrChannel returns usr channel
func (*Pid) ProcessLinks ¶
ProcessLinks returns process links
func (*Pid) RegisterPrefix ¶
RegisterPrefix registers name for process in the group of processes with
same prefix
func (*Pid) RunAfter ¶
func (pid *Pid) RunAfter(f RunTimerFunc, timeoutMs uint32) *Timer
RunAfter calls f after timeoutMs
func (*Pid) SpawnLink ¶
func (pidFrom *Pid) SpawnLink( f GenProcFunc, args ...Term) (*Pid, error)
SpawnLink makes new GenProc object, runs it's GenProcLoop and link processes
func (*Pid) SpawnOptsLink ¶
SpawnOptsLink makes new GenProc object,
runs it's GenProcLoop and link processes
func (*Pid) StopReason ¶
StopReason sends sync exit request to pid with specified reason
func (*Pid) Unregister ¶
Unregister removes process association with name
type ProcessLinksReq ¶
type ProcessLinksReq struct {
Links []*Pid
}
ProcessLinksReq is a message Links of the process
type RunTimerFunc ¶
type RunTimerFunc func()
RunTimerFunc is the type for function passed to RunAfter
type SpawnOpts ¶
type SpawnOpts struct { Prefix string Name Term UsrChanSize int SysChanSize int // contains filtered or unexported fields }
SpawnOpts is the structure to hold values of the options
func NewSpawnOpts ¶
func NewSpawnOpts() *SpawnOpts
NewSpawnOpts makes spawn object and returns object to manipulate
func (*SpawnOpts) WithLinkTo ¶
WithLinkTo sets pid to link to the process
func (*SpawnOpts) WithPrefix ¶
WithPrefix sets prefix
func (*SpawnOpts) WithSpawnOrLocate ¶
WithSpawnOrLocate sets flag to return process pid if the process with
given name and prefix already registered
func (*SpawnOpts) WithSysChannelSize ¶
WithSysChannelSize sets size of the sys channel
func (*SpawnOpts) WithTracer ¶
WithTracer sets tracer for the process
func (*SpawnOpts) WithUsrChannelSize ¶
WithUsrChannelSize sets size of the usr channel
type StopPidReq ¶
type StopPidReq struct {
Reason string
}
StopPidReq is message from pid.Stop() call
type Term ¶
type Term interface{}
Term is a type for any values
func TimerSendAfter ¶
TimerSendAfter adds one-time timer
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer to send event to pid
type Tracer ¶
type Tracer interface { // // Event handles tracer events // Event(events ...Term) }
Tracer is the interface that defines the Event method
func TracerChain ¶
TracerChain makes a chain of tracers call
Example ¶
// // tracer func // var tracerFromVar TracerFunc = func(events ...Term) { fmt.Println("tracerFromVar called") } // // tracer object // someTr := new(someTracer) tr := TracerChain( traceToTracerFunc(), tracerFromVar, TracerFunc(someTr.Trace), ) now := time.Now() call := Call{nil, &now, "test2", 124} tr.Event(&call) tr.Event(&CallResult{call, "aaa", time.Duration(5) * time.Microsecond})
Output: traceToTracerFunc called tracerFromVar called tracer with receiver traceToTracerFunc called tracerFromVar called tracer with receiver
type TracerFunc ¶
type TracerFunc func(events ...Term)
TracerFunc type is an adapter to allow to use of ordinary func as tracer