Skip to content

Commit

Permalink
removed unused method signal (#976)
Browse files Browse the repository at this point in the history
  • Loading branch information
freemanzMrojo authored Feb 13, 2025
1 parent d957e83 commit eeb6774
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 31 deletions.
16 changes: 1 addition & 15 deletions co/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import (
)

// Waiter provides channel to wait for.
// Value read from channel indicates signal or broadcast. true for signal, otherwise broadcast.
type Waiter interface {
C() <-chan bool
}

// Signal a rendezvous point for goroutines waiting for or announcing the occurrence of an event.
// It's more friendly than sync.Cond, since it's channel base. That means you can do channel selection
// It's more friendly than sync.Cond, since it's channel based. That means you can do channel selection
// to wait for an event.
type Signal struct {
l sync.Mutex
Expand All @@ -29,19 +28,6 @@ func (s *Signal) init() {
}
}

// Signal wakes one goroutine that is waiting on s.
func (s *Signal) Signal() {
s.l.Lock()

s.init()
select {
case s.ch <- true:
default:
}

s.l.Unlock()
}

// Broadcast wakes all goroutines that are waiting on s.
func (s *Signal) Broadcast() {
s.l.Lock()
Expand Down
18 changes: 2 additions & 16 deletions co/signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,7 @@ import (
"github.com/vechain/thor/v2/co"
)

func TestSignal_SignalBeforeWait(t *testing.T) {
var sig co.Signal
sig.Signal()

<-sig.NewWaiter().C()
}

func TestSignal_SignalAfterWait(t *testing.T) {
var sig co.Signal
w := sig.NewWaiter()
sig.Signal()
<-w.C()
}

func TestSignal_BroadcastBefore(t *testing.T) {
func TestSignalBroadcastBefore(t *testing.T) {
var sig co.Signal
sig.Broadcast()

Expand All @@ -46,7 +32,7 @@ func TestSignal_BroadcastBefore(t *testing.T) {
assert.Equal(t, 10, n)
}

func TestSignal_BroadcastAfterWait(t *testing.T) {
func TestSignalBroadcastAfterWait(t *testing.T) {
var sig co.Signal

var ws []co.Waiter
Expand Down

0 comments on commit eeb6774

Please sign in to comment.