Block Closure and Timeouts

Tagged:  •  

For the SS7/GSM work I am doing I have to implement dialogues with other systems and by default the IO in a lightweight process in Smalltalk is blocking (built on top of SIGIO). My problem is that a remote system could make me wait for a response forever. I am not an experienced Smalltalker yet but the existing options didn't look good enough (which might be me being unexperienced). I looked into what is required to add a #timeout:do: to the BlockClosure. The idea is to run the dialogue in a very straight forward way and guard the whole operation with a Timeout.

self sendSomething.
self waitForResponseOfKind: ABC.
self someMoreStuff.
self waitForMoe.
self askOtherSystem.
self conclude.
] timeout: 10 do: ['The operation timed out... cleanup']

It turned out to be quite easy to do in GNU Smalltalk. The BlockClosure extension creates a new Process which uses the Delay class to wait for the delay. The new delay process holds on to the BlockClosure and has a Semaphore. If the normal evaluation exists the Semaphore signals in case the timeout occurs before the original Process queues an interrupt that sends a TimeoutNotification.

Is there a better way to achieve such patterns?

Hi, have a look at Squeaks #valueWithin:onTimeout: It does what you want.

I have also used Smalltalk for carrier grade GSM/UMTS signalling. We use continuations to handle async requests.
Similar to #valueWithin:onTimeout but based on continuations.

Brent Pinkney

User login