Skip to content

Commit

Permalink
Merge pull request #2 from JosiahWitt/add-readme-license
Browse files Browse the repository at this point in the history
Add README and license
  • Loading branch information
JosiahWitt authored Mar 4, 2022
2 parents 7ef6086 + cabcf3d commit c125e0f
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Josiah Witt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# eventbus
Straightforward EventBus for Go 1.18+

[![Documentation](https://pkg.go.dev/badge/github.com/JosiahWitt/eventbus)](https://pkg.go.dev/github.com/JosiahWitt/eventbus)
[![CI](https://github.com/JosiahWitt/eventbus/workflows/CI/badge.svg)](https://github.com/JosiahWitt/eventbus/actions?query=branch%3Amain+workflow%3ACI)
[![codecov](https://codecov.io/gh/JosiahWitt/eventbus/branch/main/graph/badge.svg)](https://codecov.io/gh/JosiahWitt/eventbus)
<!-- Hiding the Go Report Card until they support generics -->
<!-- [![Go Report Card](https://goreportcard.com/badge/github.com/JosiahWitt/eventbus)](https://goreportcard.com/report/github.com/JosiahWitt/eventbus) -->

## Go Version Support
Go 1.18+ is required, due to the use of generics


## Project Status
Unlike some of my other projects that are used in production (eg. [ensure](https://github.com/JosiahWitt/ensure) for testing and [erk](https://github.com/JosiahWitt/erk) for errors), this project is _currently more on the experimental side_. It has good test coverage, but I haven't actually built anything serious with it (yet!). So, please **use at your own risk**! Oh, and if you do use it for something serious, let me know how it works out!


## Install
### Library
```bash
$ go get github.com/JosiahWitt/eventbus
```


## About
This package provides a straightforward concurrent, typed EventBus for Go 1.18+, supporting fanout, and in order, only once delivery.


## Examples

Please see the [`examples`](./examples/) directory for complete examples, such as the [Simple Chat App](./examples/simplechatapp/).

### Basic Usage
```go
type Message struct { Body string }

bus := eventbus.New[*Message]()

// In one goroutine:
sub := bus.Subscribe("chatroom:123", "user:456")
for msg := range sub.Channel() {
// Do something with msg
}
// Eventually...
sub.Unsubscribe()

// In another goroutine:
bus.Publish(&Message{Body: "Hello, World!"}, "chatroom:123", "user:789")
bus.Publish(&Message{Body: "Go is fun!"}, "chatroom:456", "user:456")
bus.Publish(&Message{Body: "Wordle 1/6"}, "chatroom:456", "user:789")
bus.Publish(&Message{Body: "Bonjour!"}, "chatroom:123", "user:456")

// sub will receive:
// 1. Hello, World!
// 2. Go is fun!
// 3. Bonjour!
// Each of those messages is published to one or both of `chatroom:123` and `user:456`.
//
// sub will not receive "Wordle 1/6", because that was published to neither `chatroom:123` nor `user:456`.
```

0 comments on commit c125e0f

Please sign in to comment.