Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtdeh committed Feb 24, 2024
1 parent 9d00780 commit 5d0d17d
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions chanswitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func repeater(b *ChanSwitch) {
func New(vals ...any) *ChanSwitch {
b := &ChanSwitch{
filters: make(map[any]*Channels),
l: sync.Mutex{},
distract: make(chan struct{}, 1),
l: sync.Mutex{},
}

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

func NewBool() *ChanSwitch {
b := &ChanSwitch{
filters: make(map[any]*Channels),
l: sync.Mutex{},
}

go repeater(b)

b.Make(true)
b.Make(false)

return b
return New(true, false)
}

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

// set filed value
func (b *ChanSwitch) Set(v any) {
fmt.Println("debug 1")
b.l.Lock()
defer b.l.Unlock()
fmt.Println("debug 2")
// get filter by value
ch := b.filters[v]
// update val
b.val = v
// distract repeated goroutines for change filter
b.distract <- struct{}{}
fmt.Println("debug 3")
// reset once channel
activeChan(ch.once)

Expand Down

0 comments on commit 5d0d17d

Please sign in to comment.