caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Samuel Mimram <smimram@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] Portable timeout function
Date: Tue, 22 Jan 2013 19:57:15 +0100	[thread overview]
Message-ID: <CA+7PP=Fd3Am2ZF5KPy+Bd7wWqnJgqdd86WG4ajPvGd8oD1G-NA@mail.gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2013-01-22 18:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-22 18:57 Samuel Mimram [this message]
2013-01-22 19:21 ` Daniel Bünzli
2013-01-23 15:03 ` AW: " Gerd Stolpmann
2013-01-27 16:23   ` Samuel Mimram

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+7PP=Fd3Am2ZF5KPy+Bd7wWqnJgqdd86WG4ajPvGd8oD1G-NA@mail.gmail.com' \
    --to=smimram@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).