Experimenting with idea of a struct called disruptor to wrap reader/writer.
diff --git a/benchmarks/default_writer_test.go b/benchmarks/default_writer_test.go
index 8514c8a..5f38da6 100644
--- a/benchmarks/default_writer_test.go
+++ b/benchmarks/default_writer_test.go
@@ -58,7 +58,7 @@
func benchmarkSequencerReservations(b *testing.B, count int64, consumers ...disruptor.Consumer) {
iterations := int64(b.N)
- writer, reader := build(consumers...)
+ myDisruptor := build(consumers...)
go func() {
b.ReportAllocs()
@@ -66,17 +66,17 @@
var sequence int64 = -1
for sequence < iterations {
- sequence = writer.Reserve(count)
+ sequence = myDisruptor.Reserve(count)
for i := sequence - (count - 1); i <= sequence; i++ {
ringBuffer[i&RingBufferMask] = i
}
- writer.Commit(sequence, sequence)
+ myDisruptor.Commit(sequence, sequence)
}
- _ = reader.Close()
+ _ = myDisruptor.Close()
}()
- reader.Read()
+ myDisruptor.Read()
}
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -94,7 +94,7 @@
}
}
-func build(consumers ...disruptor.Consumer) (disruptor.Writer, disruptor.Reader) {
+func build(consumers ...disruptor.Consumer) disruptor.Disruptor {
return disruptor.New(
disruptor.WithCapacity(RingBufferSize),
disruptor.WithConsumerGroup(consumers...))
diff --git a/disruptor.go b/disruptor.go
new file mode 100644
index 0000000..7e2a5bc
--- /dev/null
+++ b/disruptor.go
@@ -0,0 +1,13 @@
+package disruptor
+
+type Disruptor struct {
+ Writer
+ Reader
+}
+
+func NewDisruptor(writer Writer, reader Reader) Disruptor {
+ return Disruptor{
+ Writer: writer,
+ Reader: reader,
+ }
+}
diff --git a/example/main.go b/example/main.go
index 5b12222..5919d64 100644
--- a/example/main.go
+++ b/example/main.go
@@ -2,33 +2,32 @@
import (
"fmt"
- "io"
"github.com/smartystreets-prototypes/go-disruptor"
)
func main() {
- writer, reader := disruptor.New(
+ myDisruptor := disruptor.New(
disruptor.WithCapacity(BufferSize),
disruptor.WithConsumerGroup(MyConsumer{}))
- go publish(writer, reader)
+ go publish(myDisruptor)
- reader.Read()
+ myDisruptor.Read()
}
-func publish(writer disruptor.Writer, closer io.Closer) {
+func publish(myDisruptor disruptor.Disruptor) {
for sequence := int64(0); sequence <= Iterations; {
- sequence = writer.Reserve(Reservations)
+ sequence = myDisruptor.Reserve(Reservations)
for lower := sequence - Reservations + 1; lower <= sequence; lower++ {
ringBuffer[lower&BufferMask] = lower
}
- writer.Commit(sequence-Reservations+1, sequence)
+ myDisruptor.Commit(sequence-Reservations+1, sequence)
}
- _ = closer.Close()
+ _ = myDisruptor.Close()
}
// ////////////////////
diff --git a/wireup.go b/wireup.go
index 4a8a9a5..1f5a6da 100644
--- a/wireup.go
+++ b/wireup.go
@@ -9,11 +9,11 @@
}
type Option func(*Wireup)
-func New(options ...Option) (Writer, Reader) {
+func New(options ...Option) Disruptor {
if this, err := NewWireup(options...); err != nil {
panic(err)
} else {
- return this.Build()
+ return NewDisruptor(this.Build())
}
}