Module RunTimeLimit
RunTimeLimit is used to run a function thunk within a time limit, using OCaml's Unix timers and signal handling, which only allows this program to be compatible on Unix-based devices
This program also does not work with multithreading and only supports compilation with bytecode
Thanks to Gerd for the method of keeping the original signal handler behavior
Copyright (C) 2020 Nikunj Chawla
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see https://www.gnu.org/licenses/.
exceptionTimeLimitExceeded of stringTimeLimitExceededis raised if the provided thunk takes longer to execute than the provided time, taking in a string in the form "Time limit exceeded of <time> seconds" where <time> is replaced with the provided time limit
val with_time_limit : Unix.interval_timer -> float -> (unit -> 'a) -> 'awith_time_limitrunsfn_thunkfortimeseconds, returning the value returned by the execution offn_thunkif it runs within the time limit and raisingTimeLimitExceededotherwise- parameter timer
The Unix.interval_timer to use for setting a time limit on the execution time of
fn_thunk
- parameter time
The time limit to execute
fn_thunkin seconds
- parameter fn_thunk
The thunk to execute with a limit
- returns
The value returned by the execution of
fn_thunk
- raises TimeLimitExceeded
Raised if
fn_thunkdid not run within the provided time limit