Skip to content

Commit 95a76d7

Browse files
committed
Rename onceFunc type and constructor to once
1 parent f8b2fec commit 95a76d7

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

lazyClient.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ func NewMSSelect[T StringLike](c io.ReadWriteCloser, proto T) LazyConn {
1212
protos: []T{ProtocolID, proto},
1313
con: c,
1414

15-
rhandshakeOnce: newOnceFunc(),
16-
whandshakeOnce: newOnceFunc(),
15+
rhandshakeOnce: newOnce(),
16+
whandshakeOnce: newOnce(),
1717
}
1818
}
1919

@@ -25,27 +25,27 @@ func NewMultistream[T StringLike](c io.ReadWriteCloser, proto T) LazyConn {
2525
protos: []T{proto},
2626
con: c,
2727

28-
rhandshakeOnce: newOnceFunc(),
29-
whandshakeOnce: newOnceFunc(),
28+
rhandshakeOnce: newOnce(),
29+
whandshakeOnce: newOnce(),
3030
}
3131
}
3232

33-
// onceFunc is a sync.Once that can be used by synctest.
34-
// For the Multistream, it is a bit better than sync.Once because it doesn't
33+
// once is a sync.Once that can be used by synctest.
34+
// For Multistream, it is a bit better than sync.Once because it doesn't
3535
// spin when acquiring the lock.
36-
type onceFunc struct {
36+
type once struct {
3737
sem chan struct{}
3838
}
3939

40-
func newOnceFunc() *onceFunc {
41-
o := onceFunc{
40+
func newOnce() *once {
41+
o := once{
4242
sem: make(chan struct{}, 1),
4343
}
4444
o.sem <- struct{}{}
4545
return &o
4646
}
4747

48-
func (o *onceFunc) Do(f func()) {
48+
func (o *once) Do(f func()) {
4949
// We only ever pull a single value from the channel. But we want to block
5050
// Do until the first call to Do has completed. The first call will close
5151
// the channel, so by checking if it's closed we know we don't need to do
@@ -66,11 +66,11 @@ func (o *onceFunc) Do(f func()) {
6666
// See: https://github.com/multiformats/go-multistream/issues/20
6767
type lazyClientConn[T StringLike] struct {
6868
// Used to ensure we only trigger the write half of the handshake once.
69-
rhandshakeOnce *onceFunc
69+
rhandshakeOnce *once
7070
rerr error
7171

7272
// Used to ensure we only trigger the read half of the handshake once.
73-
whandshakeOnce *onceFunc
73+
whandshakeOnce *once
7474
werr error
7575

7676
// The sequence of protocols to negotiate.

multistream_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ func TestComparableErrors(t *testing.T) {
941941
}
942942

943943
func TestOnceFunc(t *testing.T) {
944-
o := newOnceFunc()
944+
o := newOnce()
945945
start := make(chan struct{})
946946
var runCount int
947947
var wg sync.WaitGroup

0 commit comments

Comments
 (0)