From b4e748a6acc800c04278daa6430a7fe0de05c23b Mon Sep 17 00:00:00 2001 From: "Denis V. Dedkov" Date: Sat, 23 Jul 2016 19:29:39 +0500 Subject: [PATCH] Timeout after unclock device --- noolite-cli.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/noolite-cli.go b/noolite-cli.go index e24e676..71a38cc 100644 --- a/noolite-cli.go +++ b/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 {