From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-3.2 required=3.0 tests=BAYES_00,NICE_REPLY_A, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R.Carter" Newsgroups: comp.lang.ada Subject: Re: wait does not perform as expected Date: Fri, 24 Feb 2023 22:16:48 +0100 Organization: A noiseless patient Spider Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 24 Feb 2023 21:16:48 -0000 (UTC) Injection-Info: reader01.eternal-september.org; posting-host="2652e59ce035a88971ee0ef0561ab440"; logging-data="2427265"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/l2s8050m4kMI+CmrHQCtlQ5vqoru+4x4=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Cancel-Lock: sha1:49fXgkPi8SsoW2hDtYUu5IVCpnI= In-Reply-To: Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:64985 List-Id: On 2023-02-22 17:34, Daniel Gaudry wrote: > the following code : Atio and Tio are undefined. Clearly this code is not what you are running. The important bit: > if Skip_After > 0.0 > then > > -- KEEP THE USER'S ATTENTION > while Timer < Skip_After loop > Timer := 1.0 + @; > delay 1.0; > ada.text_io.Put(Natural(Skip_After - Timer)'Img); > > --USER ENDS THE WAITING PERIOD BEFORE IT'S END ? > > > TIO.LOOK_AHEAD(ITEM => CHAR, > END_OF_LINE => HIT); > > ada.text_io.GET_IMMEDIATE(ITEM => CHAR, > AVAILABLE => HIT); > IF HIT THEN > RETURN; > END IF; > > end loop; > > -- USER WAITED FOR THE WHOLE WAITING PERIOD > -- LET HIM READ THE ZERO ON THE SCREEN > > delay 1.0; > return; > end if; Let's simplify this. Without the countdown, this can be rewritten using ATC Timed_Out : Boolean := False; ... select delay Skip_After; Timed_Out := True; then abort Ada.Text_IO.Get_Immediate (Item => Char); end select; if Timed_Out then delay 1.0; end if; return; This should be simple enough to get right. If ATC doesn't work well with this, it should still be simple enough to get right without it. To add the countdown, let's split that out into a task: declare task Timer is entry Stop; end Timer; task body Timer is ... -- Does the countdown immediately (uses the global constant Skip_After) -- Stops the countdown if Stop is called begin select delay Skip_After; Timed_Out := True; then abort Ada.Text_IO.Get_Immediate (Item => Char); Timer.Stop; end select; end; if Timed_Out then delay 1.0; end if; return; The task should be simple enough to get right, too. -- Jeff Carter "Saving keystrokes is the job of the text editor, not the programming language." Preben Randhol 64