-
Notifications
You must be signed in to change notification settings - Fork 1
/
nb-chan-thread-type.go
36 lines (30 loc) · 1.15 KB
/
nb-chan-thread-type.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
© 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
ISC License
*/
package parl
import "github.com/haraldrudell/parl/sets"
const (
// NBChanAlways configures NBChan to always have a thread
// - benefit: for empty NBChan, Send/SendMany to channel receive is faster due to avoiding thread launch
// - cost: a thread is always running instad of only running when NBChan non-empty
// - cost: Close or CloseNow must be invoked to shutdown NBChan
NBChanAlways NBChanThreadType = iota + 1
// NBChanNone configures no thread.
// - benefit: lower cpu
// - cost: data can only be received using [NBChan.Get]
NBChanNone
// NBChanOnDemand configures on-demand thread
NBChanOnDemand
)
// NBChanThreadType defines how NBChan is operating
// - [NBChanAlways] [NBChanNone] or on-demand thread
type NBChanThreadType uint8
func (n NBChanThreadType) String() (s string) {
return nbChanThreadTypeSet.StringT(n)
}
// set for [NBChanThreadType]
var nbChanThreadTypeSet = sets.NewSet[NBChanThreadType]([]sets.SetElement[NBChanThreadType]{
{ValueV: NBChanAlways, Name: "alwaysCh"},
{ValueV: NBChanNone, Name: "noCh"},
})