github.com/15mga/kiwi@v0.0.2-0.20240324021231-b95d5c3ac751/ecs/buffer.go (about) 1 package ecs 2 3 import ( 4 "sync" 5 ) 6 7 func newBuffer() *Buffer { 8 b := &Buffer{} 9 return b 10 } 11 12 type Buffer struct { 13 head *job 14 tail *job 15 } 16 17 func (b *Buffer) push(cmd JobName, data ...any) { 18 j := _JobPool.Get().(*job) 19 j.Name = cmd 20 j.Data = data 21 22 if b.head != nil { 23 b.tail.next = j 24 } else { 25 b.head = j 26 } 27 b.tail = j 28 } 29 30 var ( 31 _JobPool = sync.Pool{ 32 New: func() any { 33 return &job{} 34 }, 35 } 36 ) 37 38 type job struct { 39 Name JobName 40 Data []any 41 next *job 42 } 43 44 type ( 45 JobName = string 46 FnBufferJob func(JobName, *Buffer, []any) 47 FnJob func([]any) 48 )