Discover Packages
github.com/ysmood/goob
package
module
Version:
v0.4.0
Opens a new window with list of versions in this module.
Published: Apr 9, 2022
License: MIT
Opens a new window with license information.
Imports: 2
Opens a new window with list of imports.
Imported by: 13
Opens a new window with list of known importers.
README
README
¶
Overview
A lightweight observable lib. Go channel doesn't support unlimited buffer size,
it's a pain to decide what size to use, this lib will handle it dynamically.
unlimited buffer size
one publisher to multiple subscribers
thread-safe
subscribers never block each other
stable event order
Examples
See examples_test.go .
Benchmark
goos: darwin
goarch: amd64
pkg: github.com/ysmood/goob
cpu: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
BenchmarkPublish-12 7493547 143.9 ns/op 86 B/op 0 allocs/op
BenchmarkConsume-12 4258910 275.5 ns/op 0 B/op 0 allocs/op
Expand ▾
Collapse ▴
Documentation
¶
package main
import (
"context"
"fmt"
"time"
"github.com/ysmood/goob"
)
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
defer cancel()
// create an observable instance
ob := goob.New(ctx)
events := ob.Subscribe(context.TODO())
// publish events without blocking
ob.Publish(1)
ob.Publish(2)
ob.Publish(3)
// consume events
for e := range events {
fmt.Print(e)
}
}
Output:
123
NewPipe instance.
Pipe the Event via Write to Events. Events uses an internal buffer so it won't block Write.
type Observable struct {
}
Observable hub
Publish message to the queue
Source Files
¶
Click to show internal directories.
Click to hide internal directories.