'From Squeak3.9 of 7 November 2006 [latest update: #7067] on 6 January 2008 at 6:59:30 am'!
"Change Set: DelaySemaphore-6834-v1-laza
Date: 6 January 2008
Author: Alexander Lazarevic
Delay>>timeoutSemaphore: aSemaphore afterMSecs: anInteger did not use aSemaphore. This changeset reverts the method to use the provided semaphore again. It also contains a testSemaphore in DelayTest"!
!Delay class methodsFor: 'instance creation' stamp: 'laza 1/6/2008 06:35'!
timeoutSemaphore: aSemaphore afterMSecs: anInteger
"Create and schedule a Delay to signal the given semaphore when the given number of milliseconds has elapsed. Return the scheduled Delay. The timeout can be cancelled by sending 'unschedule' to this Delay."
"Details: This mechanism is used to provide a timeout when waiting for an external event, such as arrival of data over a network connection, to signal a semaphore. The timeout ensures that the semaphore will be signalled within a reasonable period of time even if the event fails to occur. Typically, the waiting process cancels the timeout request when awoken, then determines if the awaited event has actually occurred."
^ (self new setDelay: anInteger forSemaphore: aSemaphore) schedule
! !
!DelayTest methodsFor: 'testing' stamp: 'laza 1/6/2008 06:46'!
testSemaphore
"When we provide our own semaphore for a Delay, it should be used"
"See http://bugs.squeak.org/view.php?id=6834"
"self run: #testSemaphore"
| sem process |
sem := Semaphore new.
[
process := [Delay timeoutSemaphore: sem afterMSecs: 0. sem wait] newProcess.
process priority: Processor highIOPriority.
process resume.
self assert: process isTerminated.
] ensure: [sem signal]!
]style[(13 75 39 279)f2b,f2,f2Rhttp://bugs.squeak.org/view.php?id=6834;,f2! !
!DelayTest reorganize!
('testing' testBounds testSemaphore)
!