# Event handler

**URL:** <https://discourse.julialang.org/t/event-handler/59937>\
**Category:** General Usage\
**Created:** [April 24, 2021, 5:27pm UTC](https://discourse.julialang.org/t/event-handler/59937 "2021-04-24T17:27:21Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [April 24, 2021, 11:37pm UTC](https://discourse.julialang.org/t/event-handler/59937/5 "2021-04-24T23:37:33Z")

</div>

If you only have a couple of known events, I think a sequence of `if` is a decent approach. If the computation inside state transition is relatively small and the transitions between events have some structure (not all states jump to arbitrary state), maybe you can squeeze out some performance with `@goto`.

If you have many unknown event types, “JIT” approach may be useful. See, e.g., Catwalk.jl: [[ANN] Catwalk.jl - With dynamic dispatch to the moon! (an adaptive optimizer, aka JIT compiler)](https://discourse.julialang.org/t/ann-catwalk-jl-with-dynamic-dispatch-to-the-moon-an-adaptive-optimizer-aka-jit-compiler/57917)

> [@mschauer](#):
>
> but the small union
> 
> ```julia
> %19 = Base.getindex(f, j)::Union{typeof(f1!), typeof(f2!)}
> 
> ```
> 
> relies on the compiler

If you know the possible concrete types of `f[j]` statically, you can use a manual union splitting hack [like this](https://github.com/JuliaFolds/BangBang.jl/blob/eecbf8b4c1788e0f4a97f55497b0abb556bbdef8/src/dataframes_impl.jl#L61-L72). (This is a manual version of Catwalk.jl etc.). This is equivalent to plain `if`s, but it can be useful for code organization.

---

_[View the full topic](https://discourse.julialang.org/t/event-handler/59937)._
