stdlib

package module
v0.0.0-...-f9f89a2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: BSD-3-Clause Imports: 9 Imported by: 0

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

Examples

Constants

View Source
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

View Source
const (
	ExitNormal string = "normal"
	ExitKill   string = "kill"
	ExitKilled string = "killed"
)

Exit process reason constants

Variables

This section is empty.

Functions

func CompareRefs

func CompareRefs(a, b Ref) int

CompareRefs compare 2 Refs

func IsAlreadyRegError

func IsAlreadyRegError(err error) bool

IsAlreadyRegError checks if error is an AlreadyRegError

func IsChannelFullError

func IsChannelFullError(err error) bool

IsChannelFullError checks if error is a ChannelFullError

func IsExitNormalError

func IsExitNormalError(e error) bool

IsExitNormalError checks if error is an ExitNormalError

func IsNameEmptyError

func IsNameEmptyError(err error) bool

IsNameEmptyError checks if error is a NameEmptyError

func IsNilPidError

func IsNilPidError(err error) bool

IsNilPidError checks if error is a NilPidError

func IsNoProcError

func IsNoProcError(err error) bool

IsNoProcError checks if error is of type of noProcError

func IsNotRegError

func IsNotRegError(err error) bool

IsNotRegError checks if error is a NotRegError

func IsPrefixEmptyError

func IsPrefixEmptyError(err error) bool

IsPrefixEmptyError checks if error is a PrefixEmptyError

func TimerCancel

func TimerCancel(tref Term) error

TimerCancel deletes timer

func TimerServerStart

func TimerServerStart() (err error)

TimerServerStart starts timer GenServer

func TraceCall

func TraceCall(t Tracer, pid *Pid, tag string, arg Term) *time.Time

TraceCall sends event to tracer as message of type *Call

func TraceCallResult

func TraceCallResult(
	t Tracer, pid *Pid, start *time.Time, tag string, arg, result Term)

TraceCallResult sends event to tracer as message of type *CallResult

Types

type AsyncReq

type AsyncReq struct {
	Data Term
}

AsyncReq is an async message to process

type Call

type Call struct {
	Pid  *Pid
	Time *time.Time
	Tag  string
	Arg  Term
}

Call is a predefined tracer event for GenProc. Fired before call.

type CallResult

type CallResult struct {
	Call
	Result   Term
	Duration time.Duration
}

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 NewEnv

func NewEnv() *Env

NewEnv creates environment

func (*Env) GenServerStart

func (e *Env) GenServerStart(
	gs GenServer, args ...Term) (*Pid, error)

GenServerStart start GenServer process in specified environment

func (*Env) GenServerStartOpts

func (e *Env) GenServerStartOpts(
	gs GenServer, opts *SpawnOpts, args ...Term) (*Pid, error)

GenServerStartOpts start GenServer process in specified environment

with given options

func (*Env) MakeRef

func (e *Env) MakeRef() Ref

MakeRef returns new ref from specified environment

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) SpawnObj

func (e *Env) SpawnObj(
	gp GenProc, opts *SpawnOpts, args ...Term) (*Pid, error)

SpawnObj - function to exdend default GenProc object

func (*Env) SpawnWithOpts

func (e *Env) SpawnWithOpts(
	f GenProcFunc, opts *SpawnOpts, args ...Term) (*Pid, error)

SpawnWithOpts makes new GenProc object and runs it's GenProcLoop

func (*Env) Whereare

func (e *Env) Whereare(prefix string) (RegMap, error)

Whereare lookups processes by prefix in specified environment

func (*Env) Whereis

func (e *Env) Whereis(name Term) (*Pid, error)

Whereis lookups process by name in specified environment

func (*Env) WhereisPrefix

func (e *Env) WhereisPrefix(prefix string, name Term) (*Pid, error)

WhereisPrefix lookups process by prefix and name in specified environment

type ExitPidReq

type ExitPidReq struct {
	From   *Pid
	Reason string
	Exit   bool
}

ExitPidReq message sent to process when other linked process died or

explicitly by Exit or ExitReason

type From

type From chan<- Term

From is a channel to reply to the caller of the process

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

type GenProcFunc func(gp GenProc, args ...Term) error

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 (gps *GenProcSys) Link(pid *Pid)

Link sets link to pid

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) Self

func (gps *GenProcSys) Self() *Pid

Self returns pid of the 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 (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) InitOk

func (gs *GenServerSys) InitOk() Term

InitOk makes gsInitOk reply

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) NoReply

func (gs *GenServerSys) NoReply() Term

NoReply makes gsNoReply 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) Stop

func (gs *GenServerSys) Stop(reason string) Term

Stop makes Stop reply

func (*GenServerSys) Terminate

func (gs *GenServerSys) Terminate(reason string)

Terminate called when process died

type GsReply

type GsReply int

GsReply is a type for values returned from GenServer callbacks

type GsTimeout

type GsTimeout int

GsTimeout is a timeout message type

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

func NewSet

func NewSet() Gts

NewSet makes new set and returns table object to manipulate

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 LinkPidReq

type LinkPidReq struct {
	Pid *Pid
}

LinkPidReq is a message to link pid

type MonitorDownReq

type MonitorDownReq struct {
	MonitorRef Ref
	PidFrom    *Pid
	Reason     string
}

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

func GenServerStart(
	gs GenServer, args ...Term) (*Pid, error)

GenServerStart start GenServer process in default environment

func GenServerStartOpts

func GenServerStartOpts(
	gs GenServer, opts *SpawnOpts, args ...Term) (*Pid, error)

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 SpawnObj

func SpawnObj(
	gp GenProc, opts *SpawnOpts, args ...Term) (*Pid, error)

SpawnObj - function to exdend default GenProc object

func SpawnWithOpts

func SpawnWithOpts(
	f GenProcFunc, opts *SpawnOpts, args ...Term) (*Pid, error)

SpawnWithOpts makes new GenProc object and runs it's GenProcLoop

func Whereis

func Whereis(name Term) (*Pid, error)

Whereis lookups process by name in default environment

func WhereisPrefix

func WhereisPrefix(prefix string, name Term) (*Pid, error)

WhereisPrefix lookups process by prefix and name in default environment

func (*Pid) Alive

func (pid *Pid) Alive() error

Alive verifies that the process is alive

func (*Pid) Call

func (pid *Pid) Call(data Term) (Term, error)

Call sends sync message to the usr channel of the process

func (*Pid) CallSys

func (pid *Pid) CallSys(data Term) (Term, error)

CallSys sends sync sys message to the sys channel of the process

func (*Pid) Cast

func (pid *Pid) Cast(data Term) error

Cast sends *AsyncMsg message to the usr channel of the process

func (*Pid) Equal

func (pid *Pid) Equal(pid2 *Pid) bool

Equal compares two pids

func (*Pid) Exit

func (pid *Pid) Exit(reason string) error

Exit sends async exit request to itself process

func (*Pid) ExitReason

func (pid *Pid) ExitReason(pidTo *Pid, reason string) error

ExitReason Sends async exit request to other process

func (pid *Pid) GenServerStartLink(
	gs GenServer, opts *SpawnOpts, args ...Term) (*Pid, error)

GenServerStartLink start GenServer process in default environment

and links it to called process

func (*Pid) GetSysChannel

func (pid *Pid) GetSysChannel() <-chan Term

GetSysChannel returns sys channel

func (*Pid) GetUsrChannel

func (pid *Pid) GetUsrChannel() <-chan Term

GetUsrChannel returns usr channel

func (*Pid) ID

func (pid *Pid) ID() uint64

ID returns process identificator

func (pid *Pid) ProcessLinks() ([]*Pid, error)

ProcessLinks returns process links

func (*Pid) Register

func (pid *Pid) Register(name Term) error

Register associates the name with process

func (*Pid) RegisterPrefix

func (pid *Pid) RegisterPrefix(prefix string, name Term) error

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) Send

func (pid *Pid) Send(data Term) error

Send sends async message to the usr channel of the process

func (*Pid) SendAfter

func (pid *Pid) SendAfter(data Term, timeoutMs uint32) *Timer

SendAfter returns stoppable timer, after timeoutMs sends data event to pid

func (*Pid) SendSys

func (pid *Pid) SendSys(data Term) error

SendSys sends sys async message to the sys channel of the process

func (pidFrom *Pid) SpawnLink(
	f GenProcFunc, args ...Term) (*Pid, error)

SpawnLink makes new GenProc object, runs it's GenProcLoop and link processes

func (pidFrom *Pid) SpawnOptsLink(
	f GenProcFunc, opts *SpawnOpts, args ...Term) (*Pid, error)

SpawnOptsLink makes new GenProc object,

runs it's GenProcLoop and link processes

func (*Pid) Stop

func (pid *Pid) Stop() (err error)

Stop sends sync exit request to pid with reason ExitNormal

func (*Pid) StopReason

func (pid *Pid) StopReason(reason string) (err error)

StopReason sends sync exit request to pid with specified reason

func (*Pid) String

func (pid *Pid) String() string

String returns string presentation of pid

func (*Pid) Unregister

func (pid *Pid) Unregister(name Term) error

Unregister removes process association with name

func (*Pid) UnregisterPrefix

func (pid *Pid) UnregisterPrefix(prefix string, name Term) error

UnregisterPrefix removes prefix and name association of the process

type ProcessLinksReq

type ProcessLinksReq struct {
	Links []*Pid
}

ProcessLinksReq is a message Links of the process

type Ref

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

Ref is a unique reference

func MakeRef

func MakeRef() Ref

MakeRef returns new ref from default environment

func (Ref) String

func (r Ref) String() string

String returns string presentation of ref

type RegMap

type RegMap map[Term]*Pid

RegMap is a map of registered process names

func Whereare

func Whereare(prefix string) (RegMap, error)

Whereare lookups processes by prefix in default environment

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

func (op *SpawnOpts) WithLinkTo(pid *Pid) *SpawnOpts

WithLinkTo sets pid to link to the process

func (*SpawnOpts) WithName

func (op *SpawnOpts) WithName(name string) *SpawnOpts

WithName sets name

func (*SpawnOpts) WithPrefix

func (op *SpawnOpts) WithPrefix(prefix string) *SpawnOpts

WithPrefix sets prefix

func (*SpawnOpts) WithSpawnOrLocate

func (op *SpawnOpts) WithSpawnOrLocate() *SpawnOpts

WithSpawnOrLocate sets flag to return process pid if the process with

given name and prefix already registered

func (*SpawnOpts) WithSysChannelSize

func (op *SpawnOpts) WithSysChannelSize(size int) *SpawnOpts

WithSysChannelSize sets size of the sys channel

func (*SpawnOpts) WithTracer

func (op *SpawnOpts) WithTracer(t Tracer) *SpawnOpts

WithTracer sets tracer for the process

func (*SpawnOpts) WithUsrChannelSize

func (op *SpawnOpts) WithUsrChannelSize(size int) *SpawnOpts

WithUsrChannelSize sets size of the usr channel

type StopPidReq

type StopPidReq struct {
	Reason string
}

StopPidReq is message from pid.Stop() call

type SyncReq

type SyncReq struct {
	Data      Term
	ReplyChan chan<- Term
}

SyncReq is a sync message to process

type SysReq

type SysReq struct {
	Data      Term
	ReplyChan chan<- Term
}

SysReq is a system message to process

type Term

type Term interface{}

Term is a type for any values

func TimerSendAfter

func TimerSendAfter(timeMs uint32, pid *Pid, msg Term) (Term, error)

TimerSendAfter adds one-time timer

func TimerSendInterval

func TimerSendInterval(timeMs uint32, pid *Pid, msg Term) (Term, error)

TimerSendInterval adds interval timer

type Timer

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

Timer to send event to pid

func (*Timer) Stop

func (t *Timer) Stop()

Stop stops the timer

type Tracer

type Tracer interface {
	//
	// Event handles tracer events
	//
	Event(events ...Term)
}

Tracer is the interface that defines the Event method

func TracerChain

func TracerChain(outer Tracer, rest ...Tracer) Tracer

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

func TraceToConsole

func TraceToConsole() TracerFunc

TraceToConsole prints messages to console

func (TracerFunc) Event

func (f TracerFunc) Event(events ...Term)

Event implements TracerFunc

type UnlinkPidReq

type UnlinkPidReq struct {
	Pid *Pid
}

UnlinkPidReq is a message to unlink pid

Jump to

Keyboard shortcuts

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