Skip to content

Commit 5d0d17d

Browse files
committed
update
1 parent 9d00780 commit 5d0d17d

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

chanswitch.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ func repeater(b *ChanSwitch) {
4242
func New(vals ...any) *ChanSwitch {
4343
b := &ChanSwitch{
4444
filters: make(map[any]*Channels),
45-
l: sync.Mutex{},
4645
distract: make(chan struct{}, 1),
46+
l: sync.Mutex{},
4747
}
4848

4949
go repeater(b)
@@ -56,17 +56,7 @@ func New(vals ...any) *ChanSwitch {
5656
}
5757

5858
func NewBool() *ChanSwitch {
59-
b := &ChanSwitch{
60-
filters: make(map[any]*Channels),
61-
l: sync.Mutex{},
62-
}
63-
64-
go repeater(b)
65-
66-
b.Make(true)
67-
b.Make(false)
68-
69-
return b
59+
return New(true, false)
7060
}
7161

7262
func (b *ChanSwitch) Make(v any) *Channels {
@@ -84,14 +74,17 @@ func (b *ChanSwitch) Make(v any) *Channels {
8474

8575
// set filed value
8676
func (b *ChanSwitch) Set(v any) {
77+
fmt.Println("debug 1")
8778
b.l.Lock()
8879
defer b.l.Unlock()
80+
fmt.Println("debug 2")
8981
// get filter by value
9082
ch := b.filters[v]
9183
// update val
9284
b.val = v
9385
// distract repeated goroutines for change filter
9486
b.distract <- struct{}{}
87+
fmt.Println("debug 3")
9588
// reset once channel
9689
activeChan(ch.once)
9790

0 commit comments

Comments
 (0)