Understanding `select or delay until` in tasks
17 November 2023 at 06:29
Iโm playing with tasks and have a question about select
with delay until
.
I have a task with the following body (the full implementation is on GitHub):
Wait : loop
select
-- Wait for pings. When they come, reset Last_Ping.
accept Ping do
Log.Debug ("Received ping.");
Last_Ping := Clock;
end Ping;
or
-- If there is no ping within the expected interval, do something.
delay until (Last_Ping + Expected_Ping_Interval);
Log.Error ("Timeout!");
-- Do something.
-- Is there any way to keep running the task loop here?
end select;
end loop Wait;
From how I understand the select
, it waits for the specified delay - if there is a Ping
before the end of the delay, the loop iteration is finished and the next iteration is started, again waiting for the specified delay or accepting a Ping
.
Now, when the delay is over and there was no entry in Ping
, it does not proceed with the next loop iteration but is finished, right? Why is that? And is there a way to write this loop so the task continues running?
(Also happily take pointers to good resources for learning about task behavior in more depth. )
6 posts - 3 participants