From: Sergey Plaksin <serp256@gmail.com>
To: caml-list@inria.fr
Subject: Lwt_pool usage
Date: Thu, 25 Nov 2010 19:48:49 +0300 [thread overview]
Message-ID: <4CEE9371.1080806@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1165 bytes --]
lwt 2.1.1
========== Code:
open Lwt
let cococo = ref 0
let connections = Lwt_pool.create 1 (fun () -> let () = (incr cococo)
in return (string_of_int !cococo))
let test x dbh =
catch (fun _ ->
Lwt_io.printl ("Start " ^ x ^ dbh) >>
Lwt_unix.sleep 1.0 >>
Lwt_io.printl ( "[" ^ x ^ "] A " ^ dbh) >>
Lwt_unix.sleep 1.0 >>
Lwt_io.printl ( "[" ^ x^ "] B " ^ dbh) >>
Lwt_unix.sleep 1.0 >>
Lwt_io.printl ( "[" ^ x^ "] C " ^ dbh );
)
(fun e -> Lwt_io.printl ( "[" ^ x ^ "] Cancelled " ^ dbh ^ " " ^
Printexc.to_string e) >> Lwt.fail e)
let ct n = Lwt_pool.use connections (test n)
let t = Lwt.join [ct "t1"; ct "t2" ; ct "t3"; ct "t4"; ct "t5" ] in
Lwt_main.run t
============ Compilation command:
ocamlfind ocamlc -o test -syntax camlp4o -package
lwt,lwt.unix,lwt.syntax -linkpkg test.ml
====================== Output:
Start t51
[t5] A 1
[t5] B 1
[t5] C 1
Start t41
[t4] Cancelled 1 Lwt.Canceled
Start t31
[t3] Cancelled 1 Lwt.Canceled
Start t21
[t2] Cancelled 1 Lwt.Canceled
Start t11
[t1] Cancelled 1 Lwt.Canceled
Fatal error: exception Lwt.Canceled
========================
What's wrong in code? Why it raise Canceled exception?
[-- Attachment #2: Type: text/html, Size: 11448 bytes --]
next reply other threads:[~2010-11-25 16:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-25 16:48 Sergey Plaksin [this message]
2010-11-25 17:02 ` [Caml-list] " Jérémie Dimino
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=4CEE9371.1080806@gmail.com \
--to=serp256@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