Asynchronous execution inside a loop not working


#1

1) Give a description of the problem
Asynchronous execution disrupts a loop.

2) What is the expected behaviour?
When my front door is opened, store some settings in some lists about the states of Entryway_Lights, then set them to a state matching my living room (average of LightsToMatch).
When the door is closed, wait for a short period (“CloseDelay” seconds) then fade the lights to their previous state over “CloseDuration” seconds

3) What is happening/not happening?
When the delay prior to the loop (“CloseDelay”) is set to 0, the piston executes as I want. However, if I set “CloseDelay” to another number (such as 5), it will only execute one pass of the loop (the first light in the device list) and then seem to halt the piston altogether (not even logging that last i value to the console).

I’m using different methods to set the state here because any single one of them doesn’t cover all that I need: There’s not a single place I can control the fade, the color, and the color temp, so I need to use different methods based on what settings are being restored to the lights.

**4) Post a Green Snapshot of the piston

5) Attach logs after turning logging level to Full
5/15/2019, 11:49:55 AM +159ms
+1ms ╔Received event [The Bull Homestead].time = 1557938996592 with a delay of -1434ms
+188ms ║RunTime Analysis CS > 24ms > PS > 89ms > PE > 75ms > CE
+191ms ║Runtime (59905 bytes) successfully initialized in 89ms (v0.3.10a.20190223) (190ms)
+193ms ║╔Execution stage started
+271ms ║║Calculating (string) Entryway Alcove + (string) was turned off in >> (string) Entryway Alcove was turned off in
+277ms ║║Calculating (string) Entryway Alcove was turned off in + (string) 15 >> (string) Entryway Alcove was turned off in 15
+282ms ║║Calculating (string) Entryway Alcove was turned off in 15 + (string) seconds after a >> (string) Entryway Alcove was turned off in 15 seconds after a
+286ms ║║Calculating (string) Entryway Alcove was turned off in 15 seconds after a + (string) 5 >> (string) Entryway Alcove was turned off in 15 seconds after a 5
+291ms ║║Calculating (string) Entryway Alcove was turned off in 15 seconds after a 5 + (string) second delay using the LIFX Set State command. >> (string) Entryway Alcove was turned off in 15 seconds after a 5 second delay using the LIFX Set State command.
+296ms ║║Entryway Alcove was turned off in 15 seconds after a 5 second delay using the LIFX Set State command.
+301ms ║║Executed virtual command log (5ms)
+305ms ║╚Execution stage complete. (113ms)
+306ms ╚Event processed successfully (306ms)
5/15/2019, 11:49:40 AM +334ms
+1ms ╔Received event [The Bull Homestead].time = 1557938981758 with a delay of -1425ms
+203ms ║RunTime Analysis CS > 37ms > PS > 98ms > PE > 68ms > CE
+207ms ║Runtime (59905 bytes) successfully initialized in 98ms (v0.3.10a.20190223) (204ms)
+208ms ║╔Execution stage started
+258ms ║║Cancelling statement #38’s schedules…
+268ms ║║Calculating (integer) 0 + (integer) 1 >> (integer) 1
+272ms ║║Executed virtual command setVariable (2ms)
+282ms ║║Comparison (dynamic) off is_equal_to (string) on = false (2ms)
+285ms ║║Condition #47 evaluated false (9ms)
+287ms ║║Condition group #46 evaluated false (state did not change) (10ms)
+291ms ║║Cancelling statement #42’s schedules…
+1256ms ║║Executed virtual command lifxState (952ms)
+1257ms ║║Requesting a wake up for Wed, May 15 2019 @ 11:49:56 AM CDT (in 15.0s)
+1265ms ║╚Execution stage complete. (1058ms)
+1267ms ║Setting up scheduled job for Wed, May 15 2019 @ 11:49:56 AM CDT (in 14.992s)
+1276ms ╚Event processed successfully (1275ms)
5/15/2019, 11:49:36 AM +506ms
+2ms ╔Received event [Front Door].contact = closed with a delay of 132ms
+172ms ║RunTime Analysis CS > 28ms > PS > 80ms > PE > 64ms > CE
+176ms ║Runtime (59892 bytes) successfully initialized in 80ms (v0.3.10a.20190223) (173ms)
+177ms ║╔Execution stage started
+187ms ║║Comparison (enum) closed changes_to (string) open = false (1ms)
+189ms ║║Cancelling condition #2’s schedules…
+191ms ║║Condition #2 evaluated false (7ms)
+192ms ║║Cancelling condition #1’s schedules…
+193ms ║║Condition group #1 evaluated false (state changed) (10ms)
+200ms ║║Comparison (enum) closed changes_to (string) closed = true (1ms)
+202ms ║║Cancelling condition #36’s schedules…
+203ms ║║Condition #36 evaluated true (7ms)
+213ms ║║Comparison (string) off is (string) off = true (1ms)
+215ms ║║Condition #57 evaluated true (10ms)
+216ms ║║Cancelling condition #35’s schedules…
+217ms ║║Condition group #35 evaluated true (state changed) (21ms)
+220ms ║║Cancelling statement #27’s schedules…
+222ms ║║Executed virtual command cancelTasks (0ms)
+233ms ║║Calculating (string) Front door closed at + (string) Wed, May 15 2019 @ 11:49:36 AM CDT >> (string) Front door closed at Wed, May 15 2019 @ 11:49:36 AM CDT
+236ms ║║Calculating (string) Front door closed at Wed, May 15 2019 @ 11:49:36 AM CDT + (string) . >> (string) Front door closed at Wed, May 15 2019 @ 11:49:36 AM CDT.
+241ms ║║Front door closed at Wed, May 15 2019 @ 11:49:36 AM CDT.
+245ms ║║Executed virtual command log (5ms)
+249ms ║║Executed virtual command wait (1ms)
+251ms ║║Requesting a wake up for Wed, May 15 2019 @ 11:49:41 AM CDT (in 5.0s)
+256ms ║╚Execution stage complete. (79ms)
+258ms ║Setting up scheduled job for Wed, May 15 2019 @ 11:49:41 AM CDT (in 4.995s)
+268ms ╚Event processed successfully (268ms)