https://github.com/ragmaanir/besked
Small typed PubSub library for crystal.
https://github.com/ragmaanir/besked
crystal pubsub
Last synced: about 1 year ago
JSON representation
Small typed PubSub library for crystal.
- Host: GitHub
- URL: https://github.com/ragmaanir/besked
- Owner: Ragmaanir
- License: mit
- Created: 2015-11-01T18:45:58.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-11-13T05:42:37.000Z (over 9 years ago)
- Last Synced: 2025-01-14T01:12:30.155Z (about 1 year ago)
- Topics: crystal, pubsub
- Language: Crystal
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# besked [](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
```