comp.lang.ada
 help / color / mirror / Atom feed
* Abortable Timed Action
@ 2015-12-31  4:15 T.G.
  2015-12-31  6:40 ` Anh Vo
  0 siblings, 1 reply; 11+ messages in thread
From: T.G. @ 2015-12-31  4:15 UTC (permalink / raw)


Hello everyone. Is there a better way to implement a timed action?
I've tried the following :

   task type Timed_Action_Task is
     entry Exec_After (T : Duration);
     entry Cancel;
     entry Finish;
   end Timed_Action_Task;

   task body Timed_Action_Task is
      Timeout : Duration;
   begin
      loop
         select
            accept Exec_After (T : Duration) do
               Timeout := T;
            end Exec_After;
            select
               accept Cancel;
            or
               delay Timeout;
               Do_Something;
            end select;
         or
            accept Finish;
            exit;
         end select;
      end loop;
   end Timed_Action_Task;

and then later something like

  Timed_Action.Exec_After (5.0);
  ...
  if Something_Changed then
     Timed_Action.Cancel;
  end if;

it works, I've also tried,

   task body Timed_Action_Task is
      Timeout  : Duration := Duration'Last;
   begin
      loop
         select
            accept Exec_After (T : Duration) do
               Timeout := T;
            end Exec_After;
         or
            accept Cancel;
            Timeout := Duration'Last;
         or
            accept Finish;
            exit;
         or
            delay Timeout;
            Do_Something;
            Timeout := Duration'Last;
         end select;
      end loop;
   end Timed_Action_Task;

any other options?

Regards,


--- news://freenews.netfront.net/ - complaints: news@netfront.net ---

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-01-09 15:59 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-31  4:15 Abortable Timed Action T.G.
2015-12-31  6:40 ` Anh Vo
2015-12-31  7:32   ` T.G.
2015-12-31 16:21     ` Anh Vo
2015-12-31 18:09       ` T.G.
2016-01-06 21:14         ` Anh Vo
2016-01-08 20:24           ` T.G.
2016-01-09  8:45             ` Simon Wright
2016-01-09  9:10               ` Dmitry A. Kazakov
2016-01-09 14:41               ` Bob Duff
2016-01-09 15:59               ` T.G.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox