Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mikhailvs/simple-event-bus

Simple event bus for Ruby
https://github.com/mikhailvs/simple-event-bus

emit-events event-bus publish-subscribe rails ruby

Last synced: 2 months ago
JSON representation

Simple event bus for Ruby

Awesome Lists containing this project

README

        

# SimpleEventBus
[![Gem Version](https://badge.fury.io/rb/simple-event-bus.svg)](https://badge.fury.io/rb/simple-event-bus)

## Install

Gemfile:
```ruby
gem 'simple-event-bus'
```

Shell:
```sh
gem install simple-event-bus
```

## Usage
Use the `SimpleEventBus` class as a singleton, or instantiate new instances of it.

```ruby
require 'event-bus'

SimpleEventBus.subscribe(:event_happened) do |params|
puts "Event handled with block: #{params.inspect}"
end

class EventHandler
def event_happened(params)
puts "Event handled with method: #{params.inspect}"
end
end

SimpleEventBus.emit(:event_happened, param1: 'hello', param2: 'world')

bus = SimpleEventBus.new

bus.subscribe(:event_happened, EventHandler.new, once: true)

bus.emit(:event_happened, request: 'handle THIS')
```