From 7932500041954eb78d398298efc297aa8ae00182 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 10 Nov 2010 14:36:42 +0000 Subject: *** empty log message *** --- ev.pod | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'ev.pod') diff --git a/ev.pod b/ev.pod index bcea84b..a72bec9 100644 --- a/ev.pod +++ b/ev.pod @@ -3369,6 +3369,56 @@ loop!). =back +=head1 COMMON OR USEFUL IDIOMS (OR BOTH) + +This section explains some common idioms that are not immediately +obvious. Note that examples are sprinkled over the whole manual, and this +section only contains stuff that wouldn't fit anywhere else. + +=over 4 + +=item Model/nested event loop invocations and exit conditions. + +Often (especially in GUI toolkits) there are places where you have +I interaction, which is most easily implemented by recursively +invoking C. + +This brings the problem of exiting - a callback might want to finish the +main C call, but not the nested one (e.g. user clicked "Quit", but +a modal "Are you sure?" dialog is still waiting), or just the nested one +and not the main one (e.g. user clocked "Ok" in a modal dialog), or some +other combination: In these cases, C will not work alone. + +The solution is to maintain "break this loop" variable for each C +invocation, and use a loop around C until the condition is +triggered, using C: + + // main loop + int exit_main_loop = 0; + + while (!exit_main_loop) + ev_run (EV_DEFAULT_ EVRUN_ONCE); + + // in a model watcher + int exit_nested_loop = 0; + + while (!exit_nested_loop) + ev_run (EV_A_ EVRUN_ONCE); + +To exit from any of these loops, just set the corresponding exit variable: + + // exit modal loop + exit_nested_loop = 1; + + // exit main program, after modal loop is finished + exit_main_loop = 1; + + // exit both + exit_main_loop = exit_nested_loop = 1; + +=back + + =head1 LIBEVENT EMULATION Libev offers a compatibility emulation layer for libevent. It cannot @@ -3376,6 +3426,11 @@ emulate the internals of libevent, so here are some usage hints: =over 4 +=item * Only the libevent-1.4.1-beta API is being emulated. + +This was the newest libevent version available when libev was implemented, +and is still mostly uncanged in 2010. + =item * Use it by including , as usual. =item * The following members are fully supported: ev_base, ev_callback, -- cgit v1.2.3