Main Page | Report this Page
Computers Forum Index  »  Computer Languages (Smalltalk)  »  Any ideas?
Page 1 of 1    

Any ideas?

Author Message
A
Posted: Mon Jun 26, 2006 10:11 am
Guest
Hi all,

Using VisualWorks 7.3.1.

In my current project, I have a need to get user input, and have a
"timeout" with regards to the user input (say 30 seconds or a minute)
so that if the user does not enter input within that time, the program
moves on.

I have several obvious ideas, of course, using such things as Delay,
Semaphore, fork, etc. But I'm no guru when it comes to this stuff. I
could of course cobble something together rather quickly, but the
solution does not seem straightforward, and I figured some
multithreaded gurus out might know of a better or more elegant
solution.

The idea I have in my head right now is to fork off a timer and a "get
input" process, as well as putting the "main process" to sleep. If
input does not occur within the alloted time, the timer process would
have to kill off the "get input" process and reawaken the "main"
process. If input does occur, the "get input" process would have to
kill off the timer process, reawaken the "main" process, etc.

Am I thinking of this correctly? Any ideas?

Thanks so much.
A.
 
Ulli Wenk
Posted: Mon Jun 26, 2006 12:59 pm
Guest
A simple implementation is like this:

|proc theResult|
theResult := nil.
proc := [theResult := Dialog confirm: 'Are you ready now?'] fork.
30 timesRepeat:
[theResult ifNil:
[(Delay forSeconds: 1) wait]].
theResult ifNil:
[proc terminate].
Transcript show: 'Answer: ', theResult printString.

A wrote:

Quote:
In my current project, I have a need to get user input, and have a
"timeout" with regards to the user input (say 30 seconds or a minute)
so that if the user does not enter input within that time, the program
moves on.

Regards, Ulli
 
 
Page 1 of 1    
All times are GMT
The time now is Tue Dec 01, 2009 11:57 am