module EventHandler
Defined in:
event.crevent_handler.cr:1
event_handler.cr:15
events.cr
macros.cr
wrapper.cr
Constant Summary
-
VERSION =
"1.0.3"
Class Method Summary
-
.async=(async : Bool)
Asynchronous execution flag; default false.
-
.async? : Bool
Asynchronous execution flag; default false.
-
.async_send=(async_send : Bool)
Asynchronous execution flag for
#wait
ed events; default false. -
.async_send? : Bool
Asynchronous execution flag for
#wait
ed events; default false. -
.at_beginning : Int32
Default insertion index when a handler is to be inserted at the beginning of list; default 0.
-
.at_beginning=(at_beginning : Int32)
Default insertion index when a handler is to be inserted at the beginning of list; default 0.
-
.at_end : Int32
Default insertion index when a handler is to be inserted at the end of list; default -1.
-
.at_end=(at_end : Int32)
Default insertion index when a handler is to be inserted at the end of list; default -1.
-
.emit_on_remove_all=(emit_on_remove_all : Bool)
RemoveHandlerEvent
control flag for methodremove_all
; default true. -
.emit_on_remove_all? : Bool
RemoveHandlerEvent
control flag for methodremove_all
; default true.
Instance Method Summary
-
#emit(type : EventHandler::AnyEvent.class, event : EventHandler::AnyEvent)
Emits event of type.
-
#emit(type : EventHandler::AddHandlerEvent.class, event : EventHandler::AddHandlerEvent)
Emits event of type.
-
#emit(type : EventHandler::RemoveHandlerEvent.class, event : EventHandler::RemoveHandlerEvent)
Emits event of type.
-
#emit(event : EventHandler::Event)
Emits event of of type event.class
-
#emit(type : EventHandler::AnyEvent.class, *args)
Emits event of type.
-
#emit(type : EventHandler::AddHandlerEvent.class, *args)
Emits event of type.
-
#emit(type : EventHandler::RemoveHandlerEvent.class, *args)
Emits event of type.
-
#handlers(type : EventHandler::AnyEvent.class)
Returns list of handlers for event type.
-
#handlers(type : EventHandler::AddHandlerEvent.class)
Returns list of handlers for event type.
-
#handlers(type : EventHandler::RemoveHandlerEvent.class)
Returns list of handlers for event type.
-
#off(type : EventHandler::AnyEvent.class, handler : Proc(EventHandler::AnyEvent, Nil))
Removes handler from list of handlers for event type.
-
#off(type : EventHandler::AnyEvent.class, hash : UInt64)
Removes handler from list of handlers for event type.
-
#off(type : EventHandler::AnyEvent.class, wrapper : EventHandler::Wrapper(Proc(EventHandler::Event, Nil)))
Removes handler from list of handlers for event type.
-
#off(type : EventHandler::AnyEvent.class, at : Int)
Removes handler from list of handlers for event type.
-
#off(type : EventHandler::AnyEvent.class, emit = ::EventHandler.emit_on_remove_all?)
Removes all handlers for event type.
-
#off(type : EventHandler::AddHandlerEvent.class, handler : Proc(EventHandler::AddHandlerEvent, Nil))
Removes handler from list of handlers for event type.
-
#off(type : EventHandler::AddHandlerEvent.class, hash : UInt64)
Removes handler from list of handlers for event type.
-
#off(type : EventHandler::AddHandlerEvent.class, wrapper : EventHandler::Wrapper(Proc(EventHandler::Event, Nil)))
Removes handler from list of handlers for event type.
-
#off(type : EventHandler::AddHandlerEvent.class, at : Int)
Removes handler from list of handlers for event type.
-
#off(type : EventHandler::AddHandlerEvent.class, emit = ::EventHandler.emit_on_remove_all?)
Removes all handlers for event type.
-
#off(type : EventHandler::RemoveHandlerEvent.class, handler : Proc(EventHandler::RemoveHandlerEvent, Nil))
Removes handler from list of handlers for event type.
-
#off(type : EventHandler::RemoveHandlerEvent.class, hash : UInt64)
Removes handler from list of handlers for event type.
-
#off(type : EventHandler::RemoveHandlerEvent.class, wrapper : EventHandler::Wrapper(Proc(EventHandler::Event, Nil)))
Removes handler from list of handlers for event type.
-
#off(type : EventHandler::RemoveHandlerEvent.class, at : Int)
Removes handler from list of handlers for event type.
-
#off(type : EventHandler::RemoveHandlerEvent.class, emit = ::EventHandler.emit_on_remove_all?)
Removes all handlers for event type.
-
#on(type : EventHandler::AnyEvent.class, handler : Proc(EventHandler::AnyEvent, Nil), once = false, async = ::EventHandler.async?, at = ::EventHandler.at_end)
Adds handler to list of handlers for event type.
-
#on(type : EventHandler::AnyEvent.class, once = false, async = ::EventHandler.async?, at = ::EventHandler.at_end, &handler : EventHandler::AnyEvent -> Nil)
Adds handler to list of handlers for event type.
-
#on(type : EventHandler::AnyEvent.class, wrapper : EventHandler::Wrapper(Proc(EventHandler::Event, Nil)))
Adds handler to list of handlers for event type.
-
#on(type : EventHandler::AnyEvent.class, channel : Channel(EventHandler::AnyEvent), once = false, async = ::EventHandler.async?, at = ::EventHandler.at_end)
Adds an autogenerated handler which sends emitted events to channel
-
#on(type : EventHandler::AddHandlerEvent.class, handler : Proc(EventHandler::AddHandlerEvent, Nil), once = false, async = ::EventHandler.async?, at = ::EventHandler.at_end)
Adds handler to list of handlers for event type.
-
#on(type : EventHandler::AddHandlerEvent.class, once = false, async = ::EventHandler.async?, at = ::EventHandler.at_end, &handler : EventHandler::AddHandlerEvent -> Nil)
Adds handler to list of handlers for event type.
-
#on(type : EventHandler::AddHandlerEvent.class, wrapper : EventHandler::Wrapper(Proc(EventHandler::Event, Nil)))
Adds handler to list of handlers for event type.
-
#on(type : EventHandler::AddHandlerEvent.class, channel : Channel(EventHandler::AddHandlerEvent), once = false, async = ::EventHandler.async?, at = ::EventHandler.at_end)
Adds an autogenerated handler which sends emitted events to channel
-
#on(type : EventHandler::RemoveHandlerEvent.class, handler : Proc(EventHandler::RemoveHandlerEvent, Nil), once = false, async = ::EventHandler.async?, at = ::EventHandler.at_end)
Adds handler to list of handlers for event type.
-
#on(type : EventHandler::RemoveHandlerEvent.class, once = false, async = ::EventHandler.async?, at = ::EventHandler.at_end, &handler : EventHandler::RemoveHandlerEvent -> Nil)
Adds handler to list of handlers for event type.
-
#on(type : EventHandler::RemoveHandlerEvent.class, wrapper : EventHandler::Wrapper(Proc(EventHandler::Event, Nil)))
Adds handler to list of handlers for event type.
-
#on(type : EventHandler::RemoveHandlerEvent.class, channel : Channel(EventHandler::RemoveHandlerEvent), once = false, async = ::EventHandler.async?, at = ::EventHandler.at_end)
Adds an autogenerated handler which sends emitted events to channel
-
#once(type : EventHandler::AnyEvent.class, handler : Proc(EventHandler::AnyEvent, Nil), async = ::EventHandler.async?, at = ::EventHandler.at_end)
Adds handler to list of handlers for event type.
-
#once(type : EventHandler::AnyEvent.class, async = ::EventHandler.async?, at = ::EventHandler.at_end, &handler : EventHandler::AnyEvent -> Nil)
Adds handler to list of handlers for event type.
-
#once(type : EventHandler::AnyEvent.class, channel : Channel(EventHandler::AnyEvent), async = ::EventHandler.async?, at = ::EventHandler.at_end)
Adds an autogenerated handler which sends emitted events to channel After it triggers once, it is automatically removed.
-
#once(type : EventHandler::AddHandlerEvent.class, handler : Proc(EventHandler::AddHandlerEvent, Nil), async = ::EventHandler.async?, at = ::EventHandler.at_end)
Adds handler to list of handlers for event type.
-
#once(type : EventHandler::AddHandlerEvent.class, async = ::EventHandler.async?, at = ::EventHandler.at_end, &handler : EventHandler::AddHandlerEvent -> Nil)
Adds handler to list of handlers for event type.
-
#once(type : EventHandler::AddHandlerEvent.class, channel : Channel(EventHandler::AddHandlerEvent), async = ::EventHandler.async?, at = ::EventHandler.at_end)
Adds an autogenerated handler which sends emitted events to channel After it triggers once, it is automatically removed.
-
#once(type : EventHandler::RemoveHandlerEvent.class, handler : Proc(EventHandler::RemoveHandlerEvent, Nil), async = ::EventHandler.async?, at = ::EventHandler.at_end)
Adds handler to list of handlers for event type.
-
#once(type : EventHandler::RemoveHandlerEvent.class, async = ::EventHandler.async?, at = ::EventHandler.at_end, &handler : EventHandler::RemoveHandlerEvent -> Nil)
Adds handler to list of handlers for event type.
-
#once(type : EventHandler::RemoveHandlerEvent.class, channel : Channel(EventHandler::RemoveHandlerEvent), async = ::EventHandler.async?, at = ::EventHandler.at_end)
Adds an autogenerated handler which sends emitted events to channel After it triggers once, it is automatically removed.
-
#remove_all_handlers(type : EventHandler::AnyEvent.class, emit = ::EventHandler.emit_on_remove_all?)
Removes all handlers for event type.
-
#remove_all_handlers(type : EventHandler::AddHandlerEvent.class, emit = ::EventHandler.emit_on_remove_all?)
Removes all handlers for event type.
-
#remove_all_handlers(type : EventHandler::RemoveHandlerEvent.class, emit = ::EventHandler.emit_on_remove_all?)
Removes all handlers for event type.
-
#wait(type : EventHandler::AnyEvent.class, handler : Proc(EventHandler::AnyEvent, Nil) | Nil, async = ::EventHandler.async?, at = ::EventHandler.at_end, async_send = ::EventHandler.async_send?)
Blocks until event type is emitted and executes handler.
-
#wait(type : EventHandler::AnyEvent.class, async = ::EventHandler.async?, at = ::EventHandler.at_end, async_send = ::EventHandler.async_send?, &handler : EventHandler::AnyEvent -> Nil)
Blocks until event type is emitted and executes handler.
-
#wait(type : EventHandler::AnyEvent.class, async_send = ::EventHandler.async_send?, at = ::EventHandler.at_end)
Blocks until event type is emitted and returns emitted event.
-
#wait(type : EventHandler::AddHandlerEvent.class, handler : Proc(EventHandler::AddHandlerEvent, Nil) | Nil, async = ::EventHandler.async?, at = ::EventHandler.at_end, async_send = ::EventHandler.async_send?)
Blocks until event type is emitted and executes handler.
-
#wait(type : EventHandler::AddHandlerEvent.class, async = ::EventHandler.async?, at = ::EventHandler.at_end, async_send = ::EventHandler.async_send?, &handler : EventHandler::AddHandlerEvent -> Nil)
Blocks until event type is emitted and executes handler.
-
#wait(type : EventHandler::AddHandlerEvent.class, async_send = ::EventHandler.async_send?, at = ::EventHandler.at_end)
Blocks until event type is emitted and returns emitted event.
-
#wait(type : EventHandler::RemoveHandlerEvent.class, handler : Proc(EventHandler::RemoveHandlerEvent, Nil) | Nil, async = ::EventHandler.async?, at = ::EventHandler.at_end, async_send = ::EventHandler.async_send?)
Blocks until event type is emitted and executes handler.
-
#wait(type : EventHandler::RemoveHandlerEvent.class, async = ::EventHandler.async?, at = ::EventHandler.at_end, async_send = ::EventHandler.async_send?, &handler : EventHandler::RemoveHandlerEvent -> Nil)
Blocks until event type is emitted and executes handler.
-
#wait(type : EventHandler::RemoveHandlerEvent.class, async_send = ::EventHandler.async_send?, at = ::EventHandler.at_end)
Blocks until event type is emitted and returns emitted event.
Macro Summary
-
event(e, *args)
Creates events in a single line; every event is a class inheriting from
EventHandler::Event
.
Class Method Detail
Asynchronous execution flag; default false.
This setting affects whether event handlers will be executed synchronously one by one, or asynchronously in Fibers.
To enable it, set async to true:
EventHandler.async? # => false
EventHandler.async = true
Note that this setting only affects default value.
The value can be overriden using the argument async by every handler which subscribes to an event.
Asynchronous execution flag; default false.
This setting affects whether event handlers will be executed synchronously one by one, or asynchronously in Fibers.
To enable it, set async to true:
EventHandler.async? # => false
EventHandler.async = true
Note that this setting only affects default value.
The value can be overriden using the argument async by every handler which subscribes to an event.
Asynchronous execution flag for #wait
ed events; default false.
This setting affects whether implicitly created event handlers which forward events through channels will execute synchronously or asynchronously.
To enable it, set async_send to true:
EventHandler.async_send? # => false
EventHandler.async_send = true
Note that this setting only affects default value.
The value can be overriden
using the argument async_send on every #wait
.
Asynchronous execution flag for #wait
ed events; default false.
This setting affects whether implicitly created event handlers which forward events through channels will execute synchronously or asynchronously.
To enable it, set async_send to true:
EventHandler.async_send? # => false
EventHandler.async_send = true
Note that this setting only affects default value.
The value can be overriden
using the argument async_send on every #wait
.
Default insertion index when a handler is to be inserted at the beginning of list; default 0.
Changing this value might cause "Index out of bounds" Exceptions if used without additional considerations, and changing it should rarely be needed.
Default insertion index when a handler is to be inserted at the beginning of list; default 0.
Changing this value might cause "Index out of bounds" Exceptions if used without additional considerations, and changing it should rarely be needed.
Default insertion index when a handler is to be inserted at the end of list; default -1.
Changing this value might cause "Index out of bounds" Exceptions if used without additional considerations, and changing it should rarely be needed.
Default insertion index when a handler is to be inserted at the end of list; default -1.
Changing this value might cause "Index out of bounds" Exceptions if used without additional considerations, and changing it should rarely be needed.
RemoveHandlerEvent
control flag for method remove_all
; default true.
It controls whether all handlers removed as part of executing #remove_all
will
emit a RemoveHandlerEvent
. By default, this setting is true.
Disabling it could make sense at application shutdown when executing
installed RemoveHandlerEvent
handlers is not important.
To disable it, set emit_on_remove_all to false:
EventHandler.emit_on_remove_all? # => true
EventHandler.emit_on_remove_all = false
RemoveHandlerEvent
control flag for method remove_all
; default true.
It controls whether all handlers removed as part of executing #remove_all
will
emit a RemoveHandlerEvent
. By default, this setting is true.
Disabling it could make sense at application shutdown when executing
installed RemoveHandlerEvent
handlers is not important.
To disable it, set emit_on_remove_all to false:
EventHandler.emit_on_remove_all? # => true
EventHandler.emit_on_remove_all = false
Instance Method Detail
Emits event of type.
Emits event of type.
Emits event of type.
Returns list of handlers for event type.
Removes handler from list of handlers for event type.
Removes handler from list of handlers for event type.
Removes handler from list of handlers for event type.
Removes handler from list of handlers for event type.
Removes all handlers for event type.
If emit is false, RemoveHandlerEvent
s are not emitted.
If emit is true, RemoveHandlerEvent
s is emitted once for every distinct Wrapper
object removed.
See README for detailed description of this behavior.
Removes handler from list of handlers for event type.
Removes handler from list of handlers for event type.
Removes handler from list of handlers for event type.
Removes handler from list of handlers for event type.
Removes all handlers for event type.
If emit is false, RemoveHandlerEvent
s are not emitted.
If emit is true, RemoveHandlerEvent
s is emitted once for every distinct Wrapper
object removed.
See README for detailed description of this behavior.
Removes handler from list of handlers for event type.
Removes handler from list of handlers for event type.
Removes handler from list of handlers for event type.
Removes handler from list of handlers for event type.
Removes all handlers for event type.
If emit is false, RemoveHandlerEvent
s are not emitted.
If emit is true, RemoveHandlerEvent
s is emitted once for every distinct Wrapper
object removed.
See README for detailed description of this behavior.
Adds handler to list of handlers for event type.
Adds handler to list of handlers for event type.
Adds handler to list of handlers for event type.
Adds an autogenerated handler which sends emitted events to channel
Adds handler to list of handlers for event type.
Adds handler to list of handlers for event type.
Adds handler to list of handlers for event type.
Adds an autogenerated handler which sends emitted events to channel
Adds handler to list of handlers for event type.
Adds handler to list of handlers for event type.
Adds handler to list of handlers for event type.
Adds an autogenerated handler which sends emitted events to channel
Adds handler to list of handlers for event type. After it triggers once, it is automatically removed.
The same behavior is obtained using #on
and providing argument once.
Adds handler to list of handlers for event type. After it triggers once, it is automatically removed.
The same behavior is obtained using #on
and providing argument once.
Adds an autogenerated handler which sends emitted events to channel After it triggers once, it is automatically removed.
The same behavior is obtained using #on
and providing argument once.
Adds handler to list of handlers for event type. After it triggers once, it is automatically removed.
The same behavior is obtained using #on
and providing argument once.
Adds handler to list of handlers for event type. After it triggers once, it is automatically removed.
The same behavior is obtained using #on
and providing argument once.
Adds an autogenerated handler which sends emitted events to channel After it triggers once, it is automatically removed.
The same behavior is obtained using #on
and providing argument once.
Adds handler to list of handlers for event type. After it triggers once, it is automatically removed.
The same behavior is obtained using #on
and providing argument once.
Adds handler to list of handlers for event type. After it triggers once, it is automatically removed.
The same behavior is obtained using #on
and providing argument once.
Adds an autogenerated handler which sends emitted events to channel After it triggers once, it is automatically removed.
The same behavior is obtained using #on
and providing argument once.
Removes all handlers for event type.
If emit is false, RemoveHandlerEvent
s are not emitted.
If emit is true, RemoveHandlerEvent
s is emitted once for every distinct Wrapper
object removed.
See README for detailed description of this behavior.
Removes all handlers for event type.
If emit is false, RemoveHandlerEvent
s are not emitted.
If emit is true, RemoveHandlerEvent
s is emitted once for every distinct Wrapper
object removed.
See README for detailed description of this behavior.
Removes all handlers for event type.
If emit is false, RemoveHandlerEvent
s are not emitted.
If emit is true, RemoveHandlerEvent
s is emitted once for every distinct Wrapper
object removed.
See README for detailed description of this behavior.
Blocks until event type is emitted and executes handler.
Blocks until event type is emitted and executes handler.
Blocks until event type is emitted and returns emitted event.
Blocks until event type is emitted and executes handler.
Blocks until event type is emitted and executes handler.
Blocks until event type is emitted and returns emitted event.
Blocks until event type is emitted and executes handler.
Blocks until event type is emitted and executes handler.
Blocks until event type is emitted and returns emitted event.
Macro Detail
Creates events in a single line; every event is a class inheriting from EventHandler::Event
.
Since events are classes, they can be also created manually.
See EventHandler::Event
for more details.
event MouseClick, x : ::Int32, y : ::Int32