Documentation ¶
Index ¶
- Constants
- Variables
- func ContextID(ctx context.Context) (contextID string)
- func GoChain(g parl.GoGen) (s string)
- func GoErrorDump(goError parl.GoError) (s string)
- func GoNo(g parl.GoGen) (goNo string)
- func NewGoError(err error, errContext parl.GoErrorContext, g0 parl.Go) (goError parl.GoError)
- func NewGoGroup(ctx context.Context, onFirstFatal ...parl.GoFatalCallback) (g0 parl.GoGroup)
- func Parent(g parl.GoGen) (parent parl.GoGen)
- func Shorts(threads []parl.ThreadData) (s string)
- type Go
- func (g *Go) AddError(err error)
- func (g *Go) Creator() (threadID parl.ThreadID, createLocation *pruntime.CodeLocation)
- func (g *Go) Done(errp *error)
- func (i *Go) EntityID() (id parl.GoEntityID)
- func (g *Go) Go() (g00 parl.Go)
- func (g *Go) GoID() (threadID parl.ThreadID)
- func (g *Go) GoRoutine() (threadID parl.ThreadID, goFunction *pruntime.CodeLocation)
- func (g *Go) Register(label ...string) (g00 parl.Go)
- func (g *Go) String() (s string)
- func (g *Go) SubGo(onFirstFatal ...parl.GoFatalCallback) (subGo parl.SubGo)
- func (g *Go) SubGroup(onFirstFatal ...parl.GoFatalCallback) (subGroup parl.SubGroup)
- func (g *Go) ThreadInfo() (threadData parl.ThreadData)
- func (g *Go) Wait()
- func (g *Go) WaitCh() (ch parl.AwaitableCh)
- type GoError
- func (e *GoError) Err() (err error)
- func (e *GoError) ErrContext() (errContext parl.GoErrorContext)
- func (e *GoError) Error() (message string)
- func (e *GoError) Go() (g0 parl.Go)
- func (e *GoError) IsFatal() (isThreadExit bool)
- func (e *GoError) IsThreadExit() (isThreadExit bool)
- func (e *GoError) String() (s string)
- func (e *GoError) Time() (when time.Time)
- type GoGroup
- func (g *GoGroup) Add(goEntityID parl.GoEntityID, threadData *ThreadData)
- func (g *GoGroup) Cancel()
- func (g *GoGroup) CascadeEnableTermination(delta int)
- func (g *GoGroup) Ch() (ch <-chan parl.GoError)
- func (g *GoGroup) ConsumeError(goError parl.GoError)
- func (c GoGroup) Context() (ctx context.Context)
- func (g *GoGroup) EnableTermination(allowTermination bool)
- func (g *GoGroup) FirstFatal() (firstFatal *parl.OnceWaiterRO)
- func (g *GoGroup) FromGoGo() (g1 parl.Go)
- func (g *GoGroup) FromGoSubGo(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGo)
- func (g *GoGroup) FromGoSubGroup(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGroup)
- func (g *GoGroup) Go() (g1 parl.Go)
- func (g *GoGroup) GoDone(thread parl.Go, err error)
- func (g *GoGroup) IsEnableTermination() (mayTerminate bool)
- func (g *GoGroup) NamedThreads() (threads []parl.ThreadData)
- func (g *GoGroup) SetDebug(debug parl.GoDebug)
- func (g *GoGroup) String() (s string)
- func (g *GoGroup) SubGo(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGo)
- func (g *GoGroup) SubGroup(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGroup)
- func (g *GoGroup) Threads() (threads []parl.ThreadData)
- func (g *GoGroup) ThreadsInternal() (orderedMap pmaps.KeyOrderedMap[parl.GoEntityID, parl.ThreadData])
- func (g *GoGroup) UpdateThread(goEntityID parl.GoEntityID, threadData *ThreadData)
- func (g *GoGroup) Wait()
- func (g *GoGroup) WaitCh() (ch parl.AwaitableCh)
- type ThreadData
- func (td *ThreadData) Create() (createLocation *pruntime.CodeLocation)
- func (td *ThreadData) Func() (funcLocation *pruntime.CodeLocation)
- func (td *ThreadData) Get() (threadID parl.ThreadID, createLocation pruntime.CodeLocation, ...)
- func (t *ThreadData) LabeledString() (s string)
- func (td *ThreadData) Name() (label string)
- func (td *ThreadData) SetCreator(cl *pruntime.CodeLocation)
- func (td *ThreadData) Short() (s string)
- func (t *ThreadData) String() (s string)
- func (td *ThreadData) ThreadID() (threadID parl.ThreadID)
- func (td *ThreadData) Update(threadID parl.ThreadID, createInvocation, goFunction *pruntime.CodeLocation, ...)
- type ThreadLogger
- type ThreadSafeThreadData
- func (tw *ThreadSafeThreadData) Get() (thread *ThreadData)
- func (tw *ThreadSafeThreadData) HaveThreadID() (haveThreadID bool)
- func (tw *ThreadSafeThreadData) SetCreator(cl *pruntime.CodeLocation)
- func (tw *ThreadSafeThreadData) ThreadID() (threadID parl.ThreadID)
- func (tw *ThreadSafeThreadData) Update(threadID parl.ThreadID, createInvocation *pruntime.CodeLocation, ...)
Constants ¶
const ( ThreadDataEmpty = "[empty]" ThreadDataNil = "threadData:nil" )
Variables ¶
var GoGroupFactory parl.GoFactory = &goGroupFactory{}
Functions ¶
func GoErrorDump ¶ added in v0.4.82
GoErrorDump prints everything about parl.GoError
- parl.GoError: type: *g0.GoError
- err: pnet.InterfaceAddrs netInterface.Addrs route ip+net: invalid network interface at pnet.InterfaceAddrs()-interface.go:30
- t: 2023-05-10 15:53:07.885969000-07:00
- errContext: GeLocalChan
- goroutine: 72_func:g5.(*Netlink).streamReaderThread()-netlink.go:156_cre:g5.(*Netlink).ReaderThread()-netlink.go:79
func NewGoError ¶
NewGoError creates a GoError based on an error
func NewGoGroup ¶ added in v0.4.19
NewGoGroup returns a stand-alone thread-group with its own error channel. Thread-safe.
- ctx is not canceled by the thread-group
- ctx may initiate thread-group Cancel
- a stand-alone GoGroup thread-group has goGroupParent nil
- non-fatal and fatal errors from the thread-group’s threads are sent on the GoGroup’s error channel
- the GoGroup processes Go invocations and thread-exits from its own threads and the threads of its subordinate thread-groups wait-group and that of its parent
- cancel of the GoGroup’s context signals termination to its own threads and all threads of its subordinate thread-groups
- the GoGroup’s context is canceled when its provided parent context is canceled or any of its threads invoke the GoGroup’s Cancel method
- the GoGroup terminates when its error channel closes from all threads in its own thread-group and that of any subordinate thread-groups have exited.
func Shorts ¶ added in v0.4.43
func Shorts(threads []parl.ThreadData) (s string)
Shorts retruns a string of Short descriptions of all threads in the slice
- string is never empty
Types ¶
type Go ¶ added in v0.4.21
type Go struct {
// contains filtered or unexported fields
}
Go supports a goroutine executing part of a thread-group. Thread-safe.
- Register allows to name the thread and collects information on the new thread
- AddError processes non-fatal errors
- Done handles thread termination and fatal errors and is deferrable. The Go thread terminates on Done invocation.
- Go creates a sibling thread object to be provided in a go statement
- SubGo creates a subordinate thread-group managed by the parent thread group. The SubGo can be independently terminated or terminated prior to thread exit.
- SubGroup creates a subordinate thread-group with its own error channel. Fatal-error thread-exits in SubGroup can be recovered locally in that thread-group
func (*Go) Creator ¶ added in v0.4.92
func (g *Go) Creator() (threadID parl.ThreadID, createLocation *pruntime.CodeLocation)
func (*Go) Done ¶ added in v0.4.21
Done handles thread exit. Deferrable
- *errp contains possible fatalk thread error
- errp can be nil
func (*Go) EntityID ¶ added in v0.4.117
func (i *Go) EntityID() (id parl.GoEntityID)
EntityID returns GoEntityID, an internal unique idntifier
func (*Go) GoRoutine ¶ added in v0.4.92
func (g *Go) GoRoutine() (threadID parl.ThreadID, goFunction *pruntime.CodeLocation)
func (*Go) SubGo ¶ added in v0.4.21
func (g *Go) SubGo(onFirstFatal ...parl.GoFatalCallback) (subGo parl.SubGo)
func (*Go) SubGroup ¶ added in v0.4.29
func (g *Go) SubGroup(onFirstFatal ...parl.GoFatalCallback) (subGroup parl.SubGroup)
func (*Go) ThreadInfo ¶ added in v0.4.29
func (g *Go) ThreadInfo() (threadData parl.ThreadData)
func (*Go) WaitCh ¶ added in v0.4.117
func (g *Go) WaitCh() (ch parl.AwaitableCh)
type GoError ¶ added in v0.4.29
type GoError struct {
// contains filtered or unexported fields
}
GoError is a wrapper around an error associating it with a Go goroutine and the situation in which this error occurred
func (*GoError) ErrContext ¶ added in v0.4.29
func (e *GoError) ErrContext() (errContext parl.GoErrorContext)
func (*GoError) Error ¶ added in v0.4.29
Error returns a human-readable error message making GoError implement error
- for nil errors, empty string is returned
func (*GoError) IsThreadExit ¶ added in v0.4.29
type GoGroup ¶ added in v0.4.19
type GoGroup struct {
// contains filtered or unexported fields
}
GoGroup is a Go thread-group. Thread-safe.
- GoGroup has its own error channel and waitgroup and no parent thread-group.
- thread exits are processed by G1Done and the g1WaitGroup
- the thread-group terminates when its erropr channel closes
- non-fatal erors are processed by ConsumeError and the error channel
- new Go threads are handled by the g1WaitGroup
- SubGroup creates a subordinate thread-group using this threadgroup’s error channel
func (*GoGroup) Add ¶ added in v0.4.19
func (g *GoGroup) Add(goEntityID parl.GoEntityID, threadData *ThreadData)
Add processes a thread from this or a subordinate thread-group
func (*GoGroup) Cancel ¶ added in v0.4.28
func (g *GoGroup) Cancel()
Cancel signals shutdown to all threads of a thread-group.
func (*GoGroup) CascadeEnableTermination ¶ added in v0.4.69
CascadeEnableTermination manipulates wait groups of this goGroup and those of its parents to allow or prevent termination
func (*GoGroup) Ch ¶ added in v0.4.20
Ch returns a channel sending the all fatal termination errors when the FailChannel option is present, or only the first when both FailChannel and StoreSubsequentFail options are present.
func (*GoGroup) ConsumeError ¶ added in v0.4.29
ConsumeError receives non-fatal errors from a Go thread. Go.AddError delegates to this method
func (GoGroup) Context ¶ added in v0.4.28
Context returns the context of this cancelAndContext.
- Context is used to detect cancel using the receive channel Context.Done.
- Context cancellation has happened when Context.Err is non-nil.
func (*GoGroup) EnableTermination ¶ added in v0.4.43
EnableTermination false prevents the SubGo or GoGroup from terminating even if the number of threads is zero
func (*GoGroup) FirstFatal ¶ added in v0.4.29
func (g *GoGroup) FirstFatal() (firstFatal *parl.OnceWaiterRO)
FirstFatal allows to await or inspect the first thread terminating with error. it is valid if this SubGo has LocalSubGo or LocalChannel options. To wait for first fatal error using multiple-semaphore mechanic:
firstFatal := g0.FirstFatal() for { select { case <-firstFatal.Ch(): …
To inspect first fatal:
if firstFatal.DidOccur() …
func (*GoGroup) FromGoGo ¶ added in v0.4.92
FromGoGo returns a parl.Go thread-features object invoked from another parl.Go object
- the Go return value is to be used as a function argument in a go-statement function-call launching a goroutine thread
func (*GoGroup) FromGoSubGo ¶ added in v0.4.92
func (g *GoGroup) FromGoSubGo(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGo)
FromGoSubGo returns a subordinate thread-group witthout an error channel. Thread-safe.
func (*GoGroup) FromGoSubGroup ¶ added in v0.4.92
func (g *GoGroup) FromGoSubGroup(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGroup)
FromGoSubGroup returns a subordinate thread-group with an error channel handling fatal errors only. Thread-safe.
func (*GoGroup) Go ¶ added in v0.4.29
Go returns a parl.Go thread-features object
- Go is invoked by a g0-package consumer
- the Go return value is to be used as a function argument in a go-statement function-call launching a goroutine thread
func (*GoGroup) GoDone ¶ added in v0.4.29
Done receives thread exits from threads in subordinate thread-groups
func (*GoGroup) IsEnableTermination ¶ added in v0.4.43
IsEnableTermination returns the state of EnableTermination, initially true
func (*GoGroup) NamedThreads ¶ added in v0.4.43
func (g *GoGroup) NamedThreads() (threads []parl.ThreadData)
threads that have been named ordered by name
func (*GoGroup) SetDebug ¶ added in v0.4.43
SetDebug enables debug logging on this particular instance
- parl.NoDebug
- parl.DebugPrint
- parl.AggregateThread
func (*GoGroup) String ¶ added in v0.4.20
g1Group#3threads:1(1)g0.TestNewG1Group-g1-group_test.go:60
func (*GoGroup) SubGo ¶ added in v0.4.29
func (g *GoGroup) SubGo(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGo)
newSubGo returns a subordinate thread-group witthout an error channel. Thread-safe.
- a SubGo has goGroupParent non-nil and isSubGo true
- the SubGo thread’s fatal and non-fatal errors are forwarded to its parent
- SubGo has FirstFatal mechanic but no error channel of its own.
- the SubGo’s Go invocations and thread-exits are processed by the SubGo’s wait-group and the thread-group of its parent
- cancel of the SubGo’s context signals termination to its own threads and all threads of its subordinate thread-groups
- the SubGo’s context is canceled when its parent’s context is canceled or any of its threads invoke the SubGo’s Cancel method
- the SubGo thread-group terminates when all threads in its own thread-group and that of any subordinate thread-groups have exited.
func (*GoGroup) SubGroup ¶ added in v0.4.29
func (g *GoGroup) SubGroup(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGroup)
newSubGroup returns a subordinate thread-group with an error channel handling fatal errors only. Thread-safe.
- a SubGroup has goGroupParent non-nil and isSubGo false
- fatal errors from the SubGroup’s threads are sent on its own error channel
- non-fatal errors from the SubGroup’s threads are forwarded to the parent
- the SubGroup’s Go invocations and thread-exits are processed in the SubGroup’s wait-group and that of its parent
- cancel of the SubGroup’s context signals termination to its own threads and all threads of its subordinate thread-groups
- the SubGroup’s context is canceled when its parent’s context is canceled or any of its threads invoke the SubGroup’s Cancel method
- SubGroup thread-group terminates when its error channel closes after all of its threads and threads of its subordinate thread-groups have exited.
func (*GoGroup) Threads ¶ added in v0.4.43
func (g *GoGroup) Threads() (threads []parl.ThreadData)
the available data for all threads
func (*GoGroup) ThreadsInternal ¶ added in v0.4.93
func (g *GoGroup) ThreadsInternal() (orderedMap pmaps.KeyOrderedMap[parl.GoEntityID, parl.ThreadData])
the available data for all threads as a map
func (*GoGroup) UpdateThread ¶ added in v0.4.29
func (g *GoGroup) UpdateThread(goEntityID parl.GoEntityID, threadData *ThreadData)
UpdateThread recursively updates thread information for a parl.Go object invoked when that Go fiorst obtains the information
func (*GoGroup) Wait ¶ added in v0.4.19
func (g *GoGroup) Wait()
Wait waits for all threads of this thread-group to terminate.
func (*GoGroup) WaitCh ¶ added in v0.4.112
func (g *GoGroup) WaitCh() (ch parl.AwaitableCh)
returns a channel that closes on subGo end similar to Wait
type ThreadData ¶ added in v0.4.29
type ThreadData struct {
// contains filtered or unexported fields
}
ThreadData contains identifiable information about a running thread.
- ThreadData does not have initialization
func (*ThreadData) Create ¶ added in v0.4.43
func (td *ThreadData) Create() (createLocation *pruntime.CodeLocation)
func (*ThreadData) Func ¶ added in v0.4.43
func (td *ThreadData) Func() (funcLocation *pruntime.CodeLocation)
func (*ThreadData) Get ¶ added in v0.4.29
func (td *ThreadData) Get() (threadID parl.ThreadID, createLocation pruntime.CodeLocation, funcLocation pruntime.CodeLocation, label string)
func (*ThreadData) LabeledString ¶ added in v0.4.92
func (t *ThreadData) LabeledString() (s string)
func (*ThreadData) Name ¶ added in v0.4.43
func (td *ThreadData) Name() (label string)
func (*ThreadData) SetCreator ¶ added in v0.4.29
func (td *ThreadData) SetCreator(cl *pruntime.CodeLocation)
SetCreator gets preliminary Go identifier: the line invoking Go()
func (*ThreadData) Short ¶ added in v0.4.43
func (td *ThreadData) Short() (s string)
"myThreadName:4"
func (*ThreadData) String ¶ added in v0.4.43
func (t *ThreadData) String() (s string)
"myThreadName:4_func:testing.tRunner()-testing.go:1446_cre:testing.(*T).Run()-testing.go:1493"
func (*ThreadData) ThreadID ¶ added in v0.4.29
func (td *ThreadData) ThreadID() (threadID parl.ThreadID)
threadID is the ID of the running thread
func (*ThreadData) Update ¶ added in v0.4.29
func (td *ThreadData) Update( threadID parl.ThreadID, createInvocation, goFunction *pruntime.CodeLocation, label string)
Update populates this object from a stack trace.
type ThreadLogger ¶ added in v0.4.29
type ThreadLogger struct { ErrCh *parl.NBChan[parl.GoError] // contains filtered or unexported fields }
ThreadLogger waits for a GoGroup, SubGo or SubGroup to terminate while printing information on threads that have yet to exit every second.
- Because the GoGroup owner needs to continue consuming the GoGroup’s error channel, ThreadLogger has built-in threading
- the returned sync.WaitGroup pointer should be used to ensure main does not exit prematurely. The WaitGroup ends when the GoGroup ends and ThreadLogger ceases output
func NewThreadLogger ¶ added in v0.4.100
func NewThreadLogger(goGen parl.GoGen, logFn ...func(format string, a ...interface{})) (threadLogger *ThreadLogger)
NewThreadLogger wraps a GoGen thread-group in a debug listener
- parl.AggregateThread is enabled for the thread-group
- ThreadLogger listens for thread-group Cancel
- Wait method ensures process does not exit prior to ThreadLogger complete
- logFn is an optional logging function, default parl.Log to stderr
Usage:
main() { var threadGroup = g0.NewGoGroup(context.Background()) defer threadGroup.Wait() defer g0.NewThreadLogger(threadGroup).Log().Wait() defer threadGroup.Cancel() … threadGroup.Cancel()
func (*ThreadLogger) Log ¶ added in v0.4.100
func (t *ThreadLogger) Log() (t2 *ThreadLogger)
Log preares the threadgroup for logging on Cancel
func (*ThreadLogger) Wait ¶ added in v0.4.100
func (t *ThreadLogger) Wait()
type ThreadSafeThreadData ¶ added in v0.4.37
type ThreadSafeThreadData struct {
// contains filtered or unexported fields
}
ThreadSafeThreadData controls access to a ThreadData object making it thread-safe.
- ThreadSafeThreadData does not have initialization
- haveThreadID indicates whether data is present
func NewThreadSafeThreadData ¶ added in v0.4.117
func NewThreadSafeThreadData() (t *ThreadSafeThreadData)
func (*ThreadSafeThreadData) Get ¶ added in v0.4.37
func (tw *ThreadSafeThreadData) Get() (thread *ThreadData)
Get returns a clone of the wrapped ThreadData object.
func (*ThreadSafeThreadData) HaveThreadID ¶ added in v0.4.37
func (tw *ThreadSafeThreadData) HaveThreadID() (haveThreadID bool)
HaveThreadID indicates whether Update has been invoked on this ThreadDataWrap object.
func (*ThreadSafeThreadData) SetCreator ¶ added in v0.4.37
func (tw *ThreadSafeThreadData) SetCreator(cl *pruntime.CodeLocation)
SetCreator gets preliminary Go identifier: the line invoking Go().
func (*ThreadSafeThreadData) ThreadID ¶ added in v0.4.37
func (tw *ThreadSafeThreadData) ThreadID() (threadID parl.ThreadID)
ThreadID returns the thread id of the running thread or zero if thread ID is missing.
func (*ThreadSafeThreadData) Update ¶ added in v0.4.37
func (tw *ThreadSafeThreadData) Update( threadID parl.ThreadID, createInvocation *pruntime.CodeLocation, goFunction *pruntime.CodeLocation, label string, )
Update populates the wrapped ThreadData from the stack trace.