timing out a method call
Brian Murphy-Dye
brian.murphydye at mac.com
Thu Oct 21 04:06:01 UTC 2004
Chris,
I've added this method to BlockContext, and made a #TimedBlockError
subclass of Error. I'm still learning, so it's not elegant, but maybe
it will be helpful to you for now.
Brian.
waitAtMost: aDuration
"
[(Delay forSeconds: 10) wait. 5] waitAtMost: 1 seconds
[5] waitAtMost: 1 seconds
[3 / 0] waitAtMost: 5 seconds
"
| answer error semaphore blockProcess waitProcess |
answer := TimedBlockError new.
semaphore := Semaphore new.
[blockProcess := [[answer := self value. semaphore signal]
on: Exception do: [:e | error := e. semaphore signal]] fork.
waitProcess := [(Delay forDuration: aDuration) wait. semaphore
signal] fork]
ensure:
[semaphore wait.
error ifNil: [blockProcess terminate].
waitProcess ifNotNil: [waitProcess terminate]].
^ error
ifNil: [answer]
ifNotNil: [error signal]
On Oct 20, 2004, at 7:05 PM, Chris Wright wrote:
> I wan't to be able to "give up" on a method call if it doesn't return
> within some time interval ... is there some way of "waiting on on a
> return value"?
> SocketStream has a timeout, but is there a more general method?
>
> like someCode value: v timeOut: t.
>
> ?
>
> thanks for the help
>
> Chris Wright
>
> _________________________________________________________________
> Win a Sony Ericsson camera phone: http://ninemsn.com.au/babesearch
>
>
More information about the Squeak-dev
mailing list
|