comp.lang.ada
 help / color / mirror / Atom feed
From: Anh Vo <anhvofrcaus@gmail.com>
Subject: Re: Abortable Timed Action
Date: Wed, 30 Dec 2015 22:40:04 -0800 (PST)
Date: 2015-12-30T22:40:04-08:00	[thread overview]
Message-ID: <de0ebff1-8925-4610-b52e-23822d1a6f06@googlegroups.com> (raw)
In-Reply-To: <n62a4f$2fdp$1@adenine.netfront.net>

On Wednesday, December 30, 2015 at 8:15:15 PM UTC-8, T.G. wrote:
> 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?

Look like your code worked like a timer. Was it your intention to create a timer?

Anh Vo


  reply	other threads:[~2015-12-31  6:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-31  4:15 Abortable Timed Action T.G.
2015-12-31  6:40 ` Anh Vo [this message]
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.
replies disabled

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