… | |
… | |
3658 | already been invoked. |
3658 | already been invoked. |
3659 | |
3659 | |
3660 | A common way around all these issues is to make sure that |
3660 | A common way around all these issues is to make sure that |
3661 | C<start_new_request> I<always> returns before the callback is invoked. If |
3661 | C<start_new_request> I<always> returns before the callback is invoked. If |
3662 | C<start_new_request> immediately knows the result, it can artificially |
3662 | C<start_new_request> immediately knows the result, it can artificially |
3663 | delay invoking the callback by e.g. using a C<prepare> or C<idle> watcher |
3663 | delay invoking the callback by using a C<prepare> or C<idle> watcher for |
3664 | for example, or more sneakily, by reusing an existing (stopped) watcher |
3664 | example, or more sneakily, by reusing an existing (stopped) watcher and |
3665 | and pushing it into the pending queue: |
3665 | pushing it into the pending queue: |
3666 | |
3666 | |
3667 | ev_set_cb (watcher, callback); |
3667 | ev_set_cb (watcher, callback); |
3668 | ev_feed_event (EV_A_ watcher, 0); |
3668 | ev_feed_event (EV_A_ watcher, 0); |
3669 | |
3669 | |
3670 | This way, C<start_new_request> can safely return before the callback is |
3670 | This way, C<start_new_request> can safely return before the callback is |
… | |
… | |
3678 | |
3678 | |
3679 | This brings the problem of exiting - a callback might want to finish the |
3679 | This brings the problem of exiting - a callback might want to finish the |
3680 | main C<ev_run> call, but not the nested one (e.g. user clicked "Quit", but |
3680 | main C<ev_run> call, but not the nested one (e.g. user clicked "Quit", but |
3681 | a modal "Are you sure?" dialog is still waiting), or just the nested one |
3681 | a modal "Are you sure?" dialog is still waiting), or just the nested one |
3682 | and not the main one (e.g. user clocked "Ok" in a modal dialog), or some |
3682 | and not the main one (e.g. user clocked "Ok" in a modal dialog), or some |
3683 | other combination: In these cases, C<ev_break> will not work alone. |
3683 | other combination: In these cases, a simple C<ev_break> will not work. |
3684 | |
3684 | |
3685 | The solution is to maintain "break this loop" variable for each C<ev_run> |
3685 | The solution is to maintain "break this loop" variable for each C<ev_run> |
3686 | invocation, and use a loop around C<ev_run> until the condition is |
3686 | invocation, and use a loop around C<ev_run> until the condition is |
3687 | triggered, using C<EVRUN_ONCE>: |
3687 | triggered, using C<EVRUN_ONCE>: |
3688 | |
3688 | |