Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/theodesp/sima
Sima is a simple object to object or broadcast dispatching system for Go
https://github.com/theodesp/sima
broadcast-reciever dispatcher golang-library object-to-object signalling
Last synced: 20 days ago
JSON representation
Sima is a simple object to object or broadcast dispatching system for Go
- Host: GitHub
- URL: https://github.com/theodesp/sima
- Owner: theodesp
- License: mit
- Created: 2018-01-08T18:12:33.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-14T13:14:57.000Z (almost 7 years ago)
- Last Synced: 2024-10-19T09:17:46.598Z (about 1 month ago)
- Topics: broadcast-reciever, dispatcher, golang-library, object-to-object, signalling
- Language: Go
- Size: 22.5 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- Contributing: CONTRIBUTING
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
README
Sima is a simple object to object or broadcast dispatching system.
Any number of interested parties can subscribe to events.
Signal receives can receive also signals from specific senders.## Installation
```bash
$ go get -u github.com/theodesp/sima
```## Usage
1. Create a topic factory and re-use it for all signals yo want to create:```go
tf := NewTopicFactory()
onStart := NewSima(tf)
onEnd := NewSima(tf)
```2. After you have created your signals, just connect handlers for a particular topic or not. If you don't specify a topic then the handler will be assigned a ALL topic that defaults as a broadcast address.
```go
// Subscribe to ALL
onStart.Connect(func(context context.Context, sender *Topic) interface{} {
fmt.PrintF("OnStart called from Sender %+v", sender)
return sender
}, "")// Subscribe to specific sender/topic
onEnd.Connect(func(context context.Context, sender *Topic) interface{} {
fmt.PrintF("onEnd called from Sender %+v", sender)
return sender
}, "on-end-sender")
```3. Now just send some messages and any registered participant will call the handler.
```go
response := onStart.Dispatch(context.Background(), "") // will handle
response := onStart.Dispatch(context.Background(), "on-start-sender") // will not handleresponse := onEnd.Dispatch(context.Background(), "") // will not handle
response := onEnd.Dispatch(context.Background(), "on-end-sender") // will handle
```* **Checking for receivers existance**
```go
onEnd.HasRecieversFor("on-end-sender") // true
onEnd.HasRecieversFor("on-start-sender") // false
```## LICENCE
Copyright © 2017 Theo Despoudis MIT license