help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] Timeouts for BlockClosures


From: Holger Hans Peter Freyther
Subject: Re: [Help-smalltalk] Timeouts for BlockClosures
Date: Sun, 03 Apr 2011 16:58:51 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.9

On 04/03/2011 03:34 PM, Paolo Bonzini wrote:
>> Is there a kind of Exception that can be thrown but not
>> caught by a 'imprecise' on:do?
> 
> No.  One may say that "on: Exception" and "on: Notification" are
> always wrong and should never be used ("on: Warning" and "on: Error"
> instead are usually fine).  Feel free to write code as if they never
> appeared in code.

Hi,
maybe you could help me to understand the Process/BlockClosure/Exception
interaction. I do have two issues. The first is that even if I manage to call
the timeout block I am still returning to the Delay and do not leave the
block. Any idea how I could leave the delay, execute all ensure blocks inside
the timeout?

Eval [
    [(Delay forSeconds: 100000) wait] timeout: 1 do: ['Timedout' printNl].
]




Notification subclass: TimeoutNotification [
]

BlockClosure extend [
    timeout: seconds do: aBlock [
        | delay sem proc value |
        sem := Semaphore new.
        proc := Processor activeProcess.

        "Start the waiting."
        [[

            "Start a process to wait in and then signal"
            [| delay |
                delay := Delay forSeconds: seconds.

                "Wait and see if it is timed out"
                (delay timedWaitOn: sem) ifTrue: [
                    proc queueInterrupt: [ ^ TimeoutNotification signal].
                ].
            ] fork.

            ^ self value.
        ] ensure: [sem signal]
        ] on: TimeoutNotification do: [
            thisContext backtrace.
            ^ aBlock value]
    ]
]



reply via email to

[Prev in Thread] Current Thread [Next in Thread]