Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/ragmaanir/besked
- Owner: Ragmaanir
- License: mit
- Created: 2015-11-01T18:45:58.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-11-13T05:42:37.000Z (about 8 years ago)
- Last Synced: 2024-11-14T08:34:03.644Z (2 months 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 [![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)
endclass MySub
include Besked::Subscriber(Int32)getter? received : Bool
getter events : Array(Int32)def initialize
@received = false
@events = [] of Int32
enddef receive(event : Int32)
@received = true
@events << event
end
endtest "local publishers and subscribers" do
pub = MyPub.new
sub = MySub.newpub.subscribe(sub)
assert !sub.received?
pub.publish(1337)
assert sub.received?
assert sub.events == [1337]
end
```