@@ -13,6 +13,7 @@ import (
13
13
"sync"
14
14
"unsafe"
15
15
16
+ infinity "github.com/Code-Hex/go-infinity-channel"
16
17
"github.com/Code-Hex/vz/v3/internal/objc"
17
18
)
18
19
@@ -81,7 +82,7 @@ type VirtualMachine struct {
81
82
82
83
type machineState struct {
83
84
state VirtualMachineState
84
- stateNotify chan VirtualMachineState
85
+ stateNotify * infinity. Channel [ VirtualMachineState ]
85
86
86
87
mu sync.RWMutex
87
88
}
@@ -104,7 +105,7 @@ func NewVirtualMachine(config *VirtualMachineConfiguration) (*VirtualMachine, er
104
105
105
106
stateHandle := cgo .NewHandle (& machineState {
106
107
state : VirtualMachineState (0 ),
107
- stateNotify : make ( chan VirtualMachineState ),
108
+ stateNotify : infinity . NewChannel [ VirtualMachineState ]( ),
108
109
})
109
110
110
111
v := & VirtualMachine {
@@ -160,8 +161,7 @@ func changeStateOnObserver(newStateRaw C.int, cgoHandlerPtr unsafe.Pointer) {
160
161
v .mu .Lock ()
161
162
newState := VirtualMachineState (newStateRaw )
162
163
v .state = newState
163
- // for non-blocking
164
- go func () { v .stateNotify <- newState }()
164
+ v .stateNotify .In () <- newState
165
165
v .mu .Unlock ()
166
166
}
167
167
@@ -188,7 +188,7 @@ func (v *VirtualMachine) StateChangedNotify() <-chan VirtualMachineState {
188
188
val , _ := v .stateHandle .Value ().(* machineState )
189
189
val .mu .RLock ()
190
190
defer val .mu .RUnlock ()
191
- return val .stateNotify
191
+ return val .stateNotify . Out ()
192
192
}
193
193
194
194
// CanStart returns true if the machine is in a state that can be started.
0 commit comments