Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
4fef37ceca | |||
0e44626c13 |
15
commands.go
15
commands.go
@ -2,7 +2,6 @@ package mpvipc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -30,21 +29,29 @@ func Quit(socket string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func Ping(socket string) bool {
|
||||
_, err := GetPID(socket)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func IsReady(ctx context.Context, socket string) <-chan bool {
|
||||
out := make(chan bool, 1)
|
||||
|
||||
go func() {
|
||||
defer close(out)
|
||||
|
||||
if Ping(socket) {
|
||||
out <- true
|
||||
return
|
||||
}
|
||||
|
||||
ticker := time.NewTicker(100 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
conn, err := net.Dial("unix", socket)
|
||||
if err == nil {
|
||||
defer conn.Close()
|
||||
if Ping(socket) {
|
||||
out <- true
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user