[help] Program immplementing an alarm

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[help] Program immplementing an alarm

Antonio Regidor García
Hi,

I'm trying to implement an alarm in Haskell and wrote the following code: http://hpaste.org/7201
But it doesn't work as expected.

The expected behaviour is: The user enters a time in minutes. If the time is reached, a bell
rings. If, before the time is reached, he press enter, the program finish and prints the elapsed
time.

The actual behaviour is: The user enters a time in minutes. If time is reached, nothing happens.
If the user press enter, the elapsed time is printed and the program finish. Also, if he pressed
enter after the time had elapsed, the bell rings.

Some ideas?

Antonio Regidor García




      ______________________________________________
Enviado desde Correo Yahoo! La bandeja de entrada más inteligente.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: [help] Program immplementing an alarm

Yitzchak Gale
Antonio Regidor García wrote:
>  I'm trying to implement an alarm in Haskell and wrote the following code: http://hpaste.org/7201
>  But it doesn't work as expected.

Hi,

The getLine function ties up stdin. So the system function isn't
able to proceed until getLine completes, even when it is in
another thread.

Try using System.Process.runInteractiveProcess instead of system.
Don't forget to call waitForProcess on the process handle
when you are finished, or you will be left with a zombie.

Hope this helps,
Yitz
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: [help] Program immplementing an alarm

Antonio Regidor García
Thanks! But, when trying to implement your solution, I recalled hWaitForInput and used it to
implement the alarm. Anyway, thanks, probably I will need that for other programas.

Antonio

> The getLine function ties up stdin. So the system function isn't
> able to proceed until getLine completes, even when it is in
> another thread.
>
> Try using System.Process.runInteractiveProcess instead of system.
> Don't forget to call waitForProcess on the process handle
> when you are finished, or you will be left with a zombie.
>
> Hope this helps,
> Yitz




      ______________________________________________
Enviado desde Correo Yahoo! La bandeja de entrada más inteligente.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe