caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Portable timeout function
@ 2013-01-22 18:57 Samuel Mimram
  2013-01-22 19:21 ` Daniel Bünzli
  2013-01-23 15:03 ` AW: " Gerd Stolpmann
  0 siblings, 2 replies; 4+ messages in thread
From: Samuel Mimram @ 2013-01-22 18:57 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 807 bytes --]

Hi,

I would like to implement a "timeout" function of type:

float -> ('a -> 'b) -> 'a -> 'b option

which takes a maximum number n of seconds to run, a function f, an argument
x, and returns Some (f x) if the computation ends before n seconds and None
otherwise. Of course, there is a simple implementation using
Unix.setitimer, but apparently it does not work under windows because of
signals implementation (and I don't have access to a windows machine...).
Since this is a pretty standard idom I expected to find it implemented in
some library, but could not find one. Also, I'd rather not heavily change
the code (i.e. monadic threads are not really an option here, and a small
function would be appreciated).

Extra points if your solution also works with js_of_ocaml! :)

Thanks!

Regards,

Samuel.

[-- Attachment #2: Type: text/html, Size: 1133 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-01-27 16:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-22 18:57 [Caml-list] Portable timeout function Samuel Mimram
2013-01-22 19:21 ` Daniel Bünzli
2013-01-23 15:03 ` AW: " Gerd Stolpmann
2013-01-27 16:23   ` Samuel Mimram

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).