Explorar o código

Timeout after unclock device

Denis V. Dedkov %!s(int64=9) %!d(string=hai) anos
pai
achega
b4e748a6ac
Modificáronse 1 ficheiros con 10 adicións e 2 borrados
  1. 10 2
      noolite-cli.go

+ 10 - 2
noolite-cli.go

@@ -9,6 +9,7 @@ import (
 	"net/http"
 	"strings"
 	"strconv"
+	"time"
 )
 
 func sendCommand(mutex *sync.Mutex, command string, channel, value, r, g, b int) error {
@@ -20,8 +21,15 @@ func sendCommand(mutex *sync.Mutex, command string, channel, value, r, g, b int)
 		return errors.New("Command was not set")
 	}
 
-	mutex.Lock()
-	defer mutex.Unlock()
+	mutex.Lock() // Lock for sync call
+
+	timedUnlock := func(m *sync.Mutex) {
+		time.Sleep(time.Millisecond * 200) // Without timeout not worked
+		m.Unlock()
+	}
+
+	defer timedUnlock(mutex)
+
 	n, err := noolite.DefaultNooliteAdapter()
 
 	if err != nil {