github.com/benz9527/xboot@v0.0.0-20240504061247-c23f15593274/lib/ipc/disruptor_intf.go (about) 1 package ipc 2 3 import ( 4 "time" 5 "unsafe" 6 7 "golang.org/x/sys/cpu" 8 9 "github.com/benz9527/xboot/lib/queue" 10 ) 11 12 const cacheLinePadSize = unsafe.Sizeof(cpu.CacheLinePad{}) 13 14 type stopper interface { 15 Start() error 16 Stop() error 17 IsStopped() bool 18 } 19 20 type Publisher[T any] interface { 21 Publish(event T) (uint64, bool, error) 22 PublishTimeout(event T, timeout time.Duration) 23 } 24 25 type Producer[T any] Publisher[T] 26 27 type BlockStrategy interface { 28 WaitFor(eqFn func() bool) 29 Done() 30 } 31 32 type EventHandler[T any] func(event T) error // OnEvent 33 34 type Subscriber[T any] interface { 35 HandleEvent(event T) error 36 } 37 38 type Sequencer interface { 39 Capacity() uint64 40 GetReadCursor() queue.RingBufferCursor 41 GetWriteCursor() queue.RingBufferCursor 42 } 43 44 type Disruptor[T any] interface { 45 Publisher[T] 46 stopper 47 RegisterSubscriber(sub Subscriber[T]) error 48 }