File tree Expand file tree Collapse file tree 1 file changed +5
-12
lines changed Expand file tree Collapse file tree 1 file changed +5
-12
lines changed Original file line number Diff line number Diff line change @@ -42,8 +42,8 @@ func repeater(b *ChanSwitch) {
42
42
func New (vals ... any ) * ChanSwitch {
43
43
b := & ChanSwitch {
44
44
filters : make (map [any ]* Channels ),
45
- l : sync.Mutex {},
46
45
distract : make (chan struct {}, 1 ),
46
+ l : sync.Mutex {},
47
47
}
48
48
49
49
go repeater (b )
@@ -56,17 +56,7 @@ func New(vals ...any) *ChanSwitch {
56
56
}
57
57
58
58
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 )
70
60
}
71
61
72
62
func (b * ChanSwitch ) Make (v any ) * Channels {
@@ -84,14 +74,17 @@ func (b *ChanSwitch) Make(v any) *Channels {
84
74
85
75
// set filed value
86
76
func (b * ChanSwitch ) Set (v any ) {
77
+ fmt .Println ("debug 1" )
87
78
b .l .Lock ()
88
79
defer b .l .Unlock ()
80
+ fmt .Println ("debug 2" )
89
81
// get filter by value
90
82
ch := b .filters [v ]
91
83
// update val
92
84
b .val = v
93
85
// distract repeated goroutines for change filter
94
86
b .distract <- struct {}{}
87
+ fmt .Println ("debug 3" )
95
88
// reset once channel
96
89
activeChan (ch .once )
97
90
You can’t perform that action at this time.
0 commit comments