time_out/4

not the nicest program I've ever seen.%

time_out(+ Goal, + Timeout, - Result)*

Execute goal Goal with time limited Timeout, where Timeout is measured in milliseconds. If the goal succeeds, unify Result with success. If the timer expires before the goal terminates, unify Result with time_out.

This command is implemented by activating an alarm at procedure entry. If the timer expires before the goal completes, the alarm will throw an exception timeout.

One should note that time_out//33 is not reentrant, that is, a goal called from time_out should never itself call time_out//33. Moreover, time_out//33 will deactivate any previous alarms set by alarm//33 and vice-versa, hence only one of these calls should be used in a program.

Last, even though the timer is set in milliseconds, the current implementation relies on alarm//33, and therefore can only offer precision on the scale of seconds.