Skip to content

Commit 2eadf2c

Browse files
committed
trylock: Use sync.Mutex in go1.18+
Go 1.18 supplements Mutex with a TryLock method. Use this directly instead of our dumb homebrew trylock mutex when Go 1.18 is in use. CI with go 1.18-beta1
1 parent 429ab90 commit 2eadf2c

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ jobs:
77
strategy:
88
matrix:
99
node-version: [14.x, 16.x]
10-
go: [1.16, 1.17]
10+
go: [1.17, 1.18.0-beta1]
1111
steps:
1212
- uses: actions/checkout@v2
1313

1414
- name: Set up Go
1515
uses: actions/setup-go@v2
1616
with:
1717
go-version: ${{ matrix.go }}
18+
stable: '!contains(${{ matrix.go }}, "beta") && !contains(${{ matrix.go }}, "rc")'
1819

1920
- name: Go Build
2021
env:

trylock/trylock.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Copyright (c) 2021, The Decred developers
22
// See LICENSE for details.
33

4+
//go:build !go1.18
5+
// +build !go1.18
6+
47
package trylock
58

69
import (

trylock/trylock_go1.18.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2021, The Decred developers
2+
// See LICENSE for details.
3+
4+
//go:build go1.18
5+
// +build go1.18
6+
7+
package trylock
8+
9+
import "sync"
10+
11+
// Mutex is just an alias for sync.Mutex in Go 1.18 onward since TryLock() was
12+
// added to the standard library.
13+
type Mutex = sync.Mutex

0 commit comments

Comments
 (0)