diff --git a/src/crystal/event_loop/libevent.cr b/src/crystal/event_loop/libevent.cr index 21ad97030336..7b45939bd537 100644 --- a/src/crystal/event_loop/libevent.cr +++ b/src/crystal/event_loop/libevent.cr @@ -15,7 +15,9 @@ class Crystal::EventLoop::LibEvent < Crystal::EventLoop {% end %} def run(blocking : Bool) : Bool - event_base.loop(once: true, nonblock: !blocking) + flags = LibEvent2::EventLoopFlags::Once + flags |= blocking ? LibEvent2::EventLoopFlags::NoExitOnEmpty : LibEvent2::EventLoopFlags::NonBlock + event_base.loop(flags) end def interrupt : Nil diff --git a/src/crystal/event_loop/libevent/event.cr b/src/crystal/event_loop/libevent/event.cr index d6b1a5dc0433..084ba30bb1d2 100644 --- a/src/crystal/event_loop/libevent/event.cr +++ b/src/crystal/event_loop/libevent/event.cr @@ -61,10 +61,7 @@ class Crystal::EventLoop::LibEvent < Crystal::EventLoop # NOTE: may return `true` even if no event has been triggered (e.g. # nonblocking), but `false` means that nothing was processed. - def loop(once : Bool, nonblock : Bool) : Bool - flags = LibEvent2::EventLoopFlags::None - flags |= LibEvent2::EventLoopFlags::Once if once - flags |= LibEvent2::EventLoopFlags::NonBlock if nonblock + def loop(flags : LibEvent2::EventLoopFlags) : Bool LibEvent2.event_base_loop(@base, flags) == 0 end diff --git a/src/crystal/event_loop/libevent/lib_event2.cr b/src/crystal/event_loop/libevent/lib_event2.cr index e8e44b0f7473..98280f407df3 100644 --- a/src/crystal/event_loop/libevent/lib_event2.cr +++ b/src/crystal/event_loop/libevent/lib_event2.cr @@ -31,8 +31,9 @@ lib LibEvent2 @[Flags] enum EventLoopFlags - Once = 0x01 - NonBlock = 0x02 + Once = 0x01 + NonBlock = 0x02 + NoExitOnEmpty = 0x04 end @[Flags]