Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Alarm: Wait for countdown before ringing #2

Open
ThomasTJdev opened this issue Jun 26, 2018 · 0 comments
Open

[Bug] Alarm: Wait for countdown before ringing #2

ThomasTJdev opened this issue Jun 26, 2018 · 0 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ThomasTJdev
Copy link
Owner

When the nimha_gateway receives a message with a trigger, it starts the trigger proc asyncCheck alarmTriggered(). Inside the trigger proc, I would like to run a loop with await sleepAsync. The loop needs to break, if the user changes the alarm status from triggered to disarmed. If the user does not change the alarm status before the countdown time, the loop will set alarm status to ringing and break.

But using await inside this proc does not work. The await never finishes - therefore the alarm will never start ringing.

Trigger proc

proc alarmTriggered*(db: DbConn, trigger, device: string) {.async.} =

Await tries inside the trigger proc

# One of many tries
proc alarmTriggerTimer() {.async.}  = 
  var counter = 0
  while true:
    waitFor sleepAsync(1000)
    inc(counter)
    if counter == countDownTime or alarmStatus != "triggered":
      break

var f = alarmTriggerTimer(countDown)
while not f.finished:
  poll(1000)
    
if f.finished:
  if alarmStatus == "triggered":
    asyncCheck alarmRinging(db, trigger, device)

# Another try
var counter = 0
while true:
  await sleepAsync(100)
  inc(counter)
  if counter == countDownTime and alarmStatus == "triggered":
    alarmRinging(db, trigger, device)
    break
  elif counter == countDownTime and alarmStatus != "triggered":
    break
@ThomasTJdev ThomasTJdev added the help wanted Extra attention is needed label Jun 26, 2018
@ThomasTJdev ThomasTJdev changed the title Alarm: Wait for countdown before ringing [Bug] Alarm: Wait for countdown before ringing Aug 2, 2018
@ThomasTJdev ThomasTJdev added the bug Something isn't working label Aug 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant