-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix chan directions for correct semantics
- Loading branch information
Showing
3 changed files
with
32 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,26 @@ | ||
# Generic PubSub | ||
# PubSub | ||
|
||
This library provides a generic implementation of pub-sub pattern using channels in Go. | ||
This library provides a generic implementation of pub-sub pattern using channels in Go. An example usage would be like: | ||
|
||
```go | ||
ps := pubsub.New[string, int]() | ||
|
||
// Produces a random integer each second and publishes | ||
// it on the "random" topic. | ||
go func() { | ||
for { | ||
ps.Publish("random", rand.Int()) | ||
time.Sleep(time.Second) | ||
} | ||
}() | ||
|
||
// Consumes produced random integers by subscribing on | ||
// the "random" topic. | ||
go func() { | ||
ch := make(chan int) | ||
ps.Subscribe("random", ch) | ||
for r := range ch { | ||
fmt.Println(r) | ||
} | ||
}() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Package pubsub provides a generic implementation of pub-sub pattern using | ||
// channels in Go. | ||
// channels. | ||
package pubsub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters