module Lwt_glib:sig
..end
Here is what you have to do to make Lwt and GTK work together:
Lwt_glib.install
at the beginning of your program (before or
after GMain.init, it does not matter)
let () = Lwt_main.run (
(* Initializes GTK. *)
ignore (GMain.init ());
(* Install Lwt<->Glib integration. *)
Lwt_glib.install ();
(* Thread which is wakeup when the main window is closed. *)
let waiter, wakener = Lwt.wait () in
(* Create a window. *)
let window = GWindow.window () in
(* Display something inside the window. *)
ignore (GMisc.label ~text:"Hello, world!" ~packing:window#add ());
(* Quit when the window is closed. *)
ignore (window#connect#destroy (Lwt.wakeup wakener));
(* Show the window. *)
window#show ();
(* Wait for it to be closed. *)
waiter
)
val install : ?mode:[ `glib_into_lwt | `lwt_into_glib ] -> unit -> unit
If mode
is `glib_into_lwt
then glib will use the Lwt main
loop, and if mode
is `lwt_into_glib
then Lwt will use the
Glib main loop.
mode
defaults to `lwt_into_glib
because it is more
portable. `glib_into_lwt
does not work under Windows and
MacOS.
If the integration is already active, this function does
nothing.
val remove : unit -> unit
val iter : bool -> unit
iter may_block
does the
same as Glib.Main.iteration may_block
but can safely be called
in a multi-threaded program, it will not block the whole
program.
For example:
let main () =
while true do
Lwt_glib.iter true
done
let thread = Thread.create main ()
Note: you can call this function only from one thread at a time,
otherwise it will raise Failure
.
val wakeup : unit -> unit