When a timeout isn't really a timeout?

In the process of debugging a stay-open applet with an Idle handler, I’ve added a getStatus() handler that returns info about the app’s status. If I call it from another script with a “simulateHang” parameter, it delays the response by 4 seconds.

Normally the handler returns in a tenth of a second, so multiple seconds would indicate that the applet is hanging somewhere. I’m using that as a signal to kill the applet and relaunch it.

The following script is set to time out after 2 seconds:

tell application "System Events" to set tmoIsRunning to exists (processes where name is "TMO.app")
if tmoIsRunning then
	tell application "TMO"

		try
			
			with timeout of 2 seconds
				
				getStatus("simulateHang")
				
			end timeout
			
		on error errMsg number errNum
			
			if (errNum is -1712) then
				
				log " TMO timed out. "
				my restartTMO()
				return "Restarting TMO."
				
			end if
			
		end try

	end tell
else
	return "TMO is not running."
end if

When I run it in SD, it restarts the applet after 2 seconds as expected. Mission accomplished and all that.

But here’s what I don’t understand: If I comment out my restartTMO(), the script prints to the log after 2 seconds, but it continues running until the 4 seconds is up. Only then does “Restarting TMO” appear in the Result pane. By trying different delays in the the getStatus() handler, I can see that the calling script doesn’t end until getStatus() returns.

It seems odd that you can time out of the operation but the script (or is it SD?) is waiting for it to finish anyway. Using ignoring application responses lets the script end on its own terms, but of course that makes the timeout superfluous.