Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/ragmaanir/besked

Small typed PubSub library for crystal.
https://github.com/ragmaanir/besked

crystal pubsub

Last synced: 13 days ago
JSON representation

Small typed PubSub library for crystal.

Awesome Lists containing this project

README

        

# besked [![Build Status](https://travis-ci.org/Ragmaanir/besked.svg?branch=master)](https://travis-ci.org/Ragmaanir/besked)

Event System for notifications similar to ActiveSupport Instrumentation.

## Installation

Add this to your application's `shard.yml`:

```yaml
dependencies:
besked:
github: ragmaanir/besked
```

## Usage

```crystal
require "besked"

class MyPub
include Besked::Publisher(Int32)
end

class MySub
include Besked::Subscriber(Int32)

getter? received : Bool
getter events : Array(Int32)

def initialize
@received = false
@events = [] of Int32
end

def receive(event : Int32)
@received = true
@events << event
end
end

test "local publishers and subscribers" do
pub = MyPub.new
sub = MySub.new

pub.subscribe(sub)

assert !sub.received?

pub.publish(1337)

assert sub.received?
assert sub.events == [1337]
end
```