|
From: | Holger Hans Peter Freyther |
Subject: | [Help-smalltalk] Timeouts for BlockClosures |
Date: | Sat, 02 Apr 2011 14:27:16 +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 |
Hi Paolo, I would like to write code like this: [ self sendStuff self handleReply self sendStuff self handleReply success... ] timeout: 10 do: [didn't finish] My first idea was to do something like this: BlockClosure extend [ timeout: aDelay do: aBlock [ | ctx ret | ctx := thisContext. [ [TimeOutHandler with: self on: ctx delay: aDelay] fork. ret := self value. ] on: TimeOutOccured: [:e | aBlock value] ^ ret ] ] and TimeOutHandler would use process queueInterrupt: [TimeOutOccured signal]. This all looks quite nice but what if I write code like this? [ [] whileTrue: [ [ self handleReply ] on: (Pokemon)Exception do: []. ] ] timeout: 10 do: [] So my questions are. Is there a kind of Exception that can be thrown but not caught by a 'imprecise' on:do? E.g. this exception can only be handled by this specific handler? Or should I use thisContext and play with the IP or is this whole idea just not the right thing to be done in smalltalk?
[Prev in Thread] | Current Thread | [Next in Thread] |