# Hanami 2.0 Ideas

**URL:** <https://discourse.hanakai.org/t/hanami-2-0-ideas/306>\
**Category:** proposals\
**Created:** [March 9, 2017, 4:03pm UTC](https://discourse.hanakai.org/t/hanami-2-0-ideas/306 "2017-03-09T16:03:52Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![jodosha](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/jodosha/32/710_2.png) [@jodosha](https://discourse.hanakai.org/u/jodosha)\
**Post date:** [March 14, 2017, 10:27am UTC](https://discourse.hanakai.org/t/hanami-2-0-ideas/306/9 "2017-03-14T10:27:16Z")

</div>

## Events/Instrumentation

Introduce an events system that can provide an API to emit/handle them. The system is similar to `ActiveSupport::Notifications`, and it should use `wisper` gem.

The idea is to “broadcast” an event happening in the framework or in a Hanami project and let the other part of the system to react to it. There are several scenarios.

#### Pub/Sub

```ruby
class WelcomeMailer
  subscribe_to "user.signup"
end

```

```ruby
class DripAdapter
  subscribe_to "user.signup"
end

```

```ruby
class Signup
  include Hanami::Interactor

  def call(data)
    user = UserRepository.new.create(data[:user])
    broadcast("user.signup", user: user)
  end
end

```

When that event is emitted, `WelcomeMailer` and `DripAdapter` will receive a notification and react accordingly.

#### Async Execution

Continuing on the previous example, the broadcast is immediate, but the execution of the receiver logic can be async. We can send to a queue system (eg. `sidekiq`) the name of the event and the payload and let it to schedule the execution.

The API could be

```ruby
broadcast("user.signup", user: user).async(...)

```

#### Instrumentation

```ruby
def render
  broadcast('rendering.template') do
    # ...
  end
end

```

This reports the elapsed time. We can use it to log when a template was rendered.

* * *

This can be part of `1.x` series.

---

_[View the full topic](https://discourse.hanakai.org/t/hanami-2-0-ideas/306)._
