Saving and resuming an exception context?

Avi Bryant avi at beta4.com
Thu Mar 25 09:12:14 UTC 2004


On Mar 24, 2004, at 4:34 PM, Ned Konz wrote:

> I'd like to be able to evaluate a block, and upon an exception freeze 
> the
> execution state so that it can be resumed later (not necessarily from 
> the
> same context). Kind of like a continuation, but without replacing the 
> current
> stack context.

Why not replacing the current stack context?  Is that an implementation 
detail or an actual requirement?

> That is:
>
> Notification subclass: FreezeMe ...
>
> MyClass>>runBlock: aBlock frozenContext: oldFrozenState
> 	| frozenState |
> 	frozenState := nil.
> 	[ oldFrozenState
> 		ifNotNil: [ oldFrozenState resumeSomehow ]
> 		ifNil: [ aBlock value ] ]
> 			on: FreezeMe
> 			do: [ :ex | frozenState := ex freezeForLater ].
> 	^frozenState
>
>

FWIW, this is how I think you would implement it using continuations.  
It has the interesting property that you can resume multiple times from 
the same frozen state.  Not tested, though.

MyClass>>runBlock: aBlock frozenContext: oldFrozenState
	|frozen|
	frozen := oldFrozenState ifNil: [
			[:f ||freeze|
			freeze := f.
			aBlock
		  		on: FreezeMe
    				do: [:ex | freeze := Continuation currentDo: [:cc | freeze 
value: cc].  ex resume]]].
	^ Continuation currentDo: [:cc | frozen value: cc. nil]




More information about the Squeak-dev mailing list