spectrum v0.2.0
Spectrum
A simple event framework using syringe DI.
Installation
-
Add the dependency to your
shard.yml
:dependencies: spectrum: github: elliotize/spectrum
-
Run
shards install
Usage
require "spectrum"
class FooBarOneEvent
include Spectrum::Event
def initialize(@id : Int32)
end
end
class FooBarTwoEvent
include Spectrum::Event
def initialize(@id : Int32)
end
end
class FooBarOneEventHandler
include Spectrum::EventHandler
Syringe.injectable
def on_event(event : FooBarOneEvent)
# Do something
end
end
class FooBarTwoEventHandler
include Spectrum::EventHandler
Syringe.injectable
def on_event(event : FooBarTwoEvent)
# Do something
end
end
class FooBarBothEventHandler
include Spectrum::EventHandler
Syringe.injectable
def on_event(event : FooBarOneEvent)
# Do something
end
def on_event(event : FooBarTwoEvent)
# Do something
end
end
## Sync event
event_one = FooBarOneEvent.new(id: 1)
Spectrum.dispatch_sync_event(event_one)
event_two = FooBarTwoEvent.new(id: 2)
Spectrum.dispatch_sync_event(event_two)
## Async event
Spectrum::EventQueue.start(:my_queue)
event_one = FooBarOneEvent.new(id: 1)
Spectrum.dispatch_async_event(event_one, :my_queue)
event_two = FooBarTwoEvent.new(id: 2)
Spectrum.dispatch_async_event(event_two, :my_queue)
Spectrum::EventQueue.stop(:my_queue)
## Advanced Queue Settings
Spectrum::EventQueue.start(
name: :my_queue,
number_of_workers: 10
queue_size: 10
)
Contributing
- Fork it (https://github.com/elliotize/spectrum/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Tom Elliot - creator and maintainer
Repository
spectrum
Owner
Statistic
- 1
- 0
- 0
- 0
- 1
- over 4 years ago
- July 12, 2019
License
MIT License
Links
Synced at
Thu, 07 Nov 2024 03:49:12 GMT
Languages