Skip to content

Commit 6c8b0b0

Browse files
authored
Merge pull request #126 from Code-Hex/add/go-infinity-channel
add go-infinity-channel
2 parents 424c865 + 00e3602 commit 6c8b0b0

File tree

10 files changed

+26
-9
lines changed

10 files changed

+26
-9
lines changed

.github/workflows/compile.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ jobs:
3030
- macOS-11
3131
- macOS-12
3232
go:
33-
- 1.18
34-
- 1.19
33+
- '^1.18'
34+
- '^1.19'
35+
- '^1.20'
3536
steps:
3637
- name: Check out repository code
3738
uses: actions/checkout@v3

example/gui-linux/go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
)
1111

1212
require (
13+
github.com/Code-Hex/go-infinity-channel v1.0.0 // indirect
1314
github.com/mattn/go-isatty v0.0.14 // indirect
1415
golang.org/x/mod v0.6.0 // indirect
1516
golang.org/x/sys v0.1.0 // indirect

example/gui-linux/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/Code-Hex/go-infinity-channel v1.0.0 h1:M8BWlfDOxq9or9yvF9+YkceoTkDI1pFAqvnP87Zh0Nw=
2+
github.com/Code-Hex/go-infinity-channel v1.0.0/go.mod h1:5yUVg/Fqao9dAjcpzoQ33WwfdMWmISOrQloDRn3bsvY=
13
github.com/Songmu/prompter v0.5.1 h1:IAsttKsOZWSDw7bV1mtGn9TAmLFAjXbp9I/eYmUUogo=
24
github.com/Songmu/prompter v0.5.1/go.mod h1:CS3jEPD6h9IaLaG6afrl1orTgII9+uDWuw95dr6xHSw=
35
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=

example/linux/go.mod

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ require (
1010
golang.org/x/sys v0.1.0
1111
)
1212

13-
require golang.org/x/mod v0.6.0 // indirect
13+
require (
14+
github.com/Code-Hex/go-infinity-channel v1.0.0 // indirect
15+
golang.org/x/mod v0.6.0 // indirect
16+
)

example/linux/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/Code-Hex/go-infinity-channel v1.0.0 h1:M8BWlfDOxq9or9yvF9+YkceoTkDI1pFAqvnP87Zh0Nw=
2+
github.com/Code-Hex/go-infinity-channel v1.0.0/go.mod h1:5yUVg/Fqao9dAjcpzoQ33WwfdMWmISOrQloDRn3bsvY=
13
github.com/pkg/term v1.1.0 h1:xIAAdCMh3QIAy+5FrE8Ad8XoDhEU4ufwbaSozViP9kk=
24
github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw=
35
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=

example/macOS/go.mod

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ replace github.com/Code-Hex/vz/v3 => ../../
66

77
require github.com/Code-Hex/vz/v3 v3.0.0-00010101000000-000000000000
88

9-
require golang.org/x/mod v0.6.0 // indirect
9+
require (
10+
github.com/Code-Hex/go-infinity-channel v1.0.0 // indirect
11+
golang.org/x/mod v0.6.0 // indirect
12+
)

example/macOS/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/Code-Hex/go-infinity-channel v1.0.0 h1:M8BWlfDOxq9or9yvF9+YkceoTkDI1pFAqvnP87Zh0Nw=
2+
github.com/Code-Hex/go-infinity-channel v1.0.0/go.mod h1:5yUVg/Fqao9dAjcpzoQ33WwfdMWmISOrQloDRn3bsvY=
13
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
24
golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I=
35
golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI=

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/Code-Hex/vz/v3
33
go 1.19
44

55
require (
6+
github.com/Code-Hex/go-infinity-channel v1.0.0
67
golang.org/x/crypto v0.1.0
78
golang.org/x/mod v0.6.0
89
)

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/Code-Hex/go-infinity-channel v1.0.0 h1:M8BWlfDOxq9or9yvF9+YkceoTkDI1pFAqvnP87Zh0Nw=
2+
github.com/Code-Hex/go-infinity-channel v1.0.0/go.mod h1:5yUVg/Fqao9dAjcpzoQ33WwfdMWmISOrQloDRn3bsvY=
13
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
24
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
35
golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I=

virtualization.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"sync"
1414
"unsafe"
1515

16+
infinity "github.com/Code-Hex/go-infinity-channel"
1617
"github.com/Code-Hex/vz/v3/internal/objc"
1718
)
1819

@@ -81,7 +82,7 @@ type VirtualMachine struct {
8182

8283
type machineState struct {
8384
state VirtualMachineState
84-
stateNotify chan VirtualMachineState
85+
stateNotify *infinity.Channel[VirtualMachineState]
8586

8687
mu sync.RWMutex
8788
}
@@ -104,7 +105,7 @@ func NewVirtualMachine(config *VirtualMachineConfiguration) (*VirtualMachine, er
104105

105106
stateHandle := cgo.NewHandle(&machineState{
106107
state: VirtualMachineState(0),
107-
stateNotify: make(chan VirtualMachineState),
108+
stateNotify: infinity.NewChannel[VirtualMachineState](),
108109
})
109110

110111
v := &VirtualMachine{
@@ -160,8 +161,7 @@ func changeStateOnObserver(newStateRaw C.int, cgoHandlerPtr unsafe.Pointer) {
160161
v.mu.Lock()
161162
newState := VirtualMachineState(newStateRaw)
162163
v.state = newState
163-
// for non-blocking
164-
go func() { v.stateNotify <- newState }()
164+
v.stateNotify.In() <- newState
165165
v.mu.Unlock()
166166
}
167167

@@ -188,7 +188,7 @@ func (v *VirtualMachine) StateChangedNotify() <-chan VirtualMachineState {
188188
val, _ := v.stateHandle.Value().(*machineState)
189189
val.mu.RLock()
190190
defer val.mu.RUnlock()
191-
return val.stateNotify
191+
return val.stateNotify.Out()
192192
}
193193

194194
// CanStart returns true if the machine is in a state that can be started.

0 commit comments

Comments
 (0)