github.com/pharosnet/flyline@v1.0.2/README.md (about) 1 # flyline 2 Fly multi-producer / multi-consumer channels for Go 3 4 A flyline buffer works similar to a standard Go channel with the following features: 5 6 - It has a sync method. That means, you can wait for all after close buffer. 7 - It is lock-free and thread-safe. 8 - By default, it does not have a cap, you can use send filter to implement it. 9 10 # Getting Started 11 12 ### Installing 13 14 To start using flyline, install Go and run `go get`: 15 16 ```sh 17 $ go get github.com/pharosnet/flyline 18 ``` 19 20 This will retrieve the library. 21 22 ### Usage 23 24 It's easily to use, like standard Go channel. 25 26 #### ArrayBuffer (it's better than go channel) 27 28 ```go 29 // buffer.go 30 package main 31 32 import ( 33 "github.com/pharosnet/flyline" 34 "time" 35 "context" 36 ) 37 38 func main() { 39 buf := flyline.NewArrayBuffer(1024*16) 40 buf.Send(time.Now()) 41 value, ok := buf.Recv() 42 recvTime := time.Time{} 43 flyline.ValueScan(value, &recvTime) 44 println(recvTime) 45 // close buffer 46 buf.Close() 47 // change ctx to timeout, if sync with timeout. 48 buf.Sync(context.Background()) 49 } 50 ``` 51 52 ```sh 53 $ go run buffer.go 54 ``` 55 56 57 58 #### QueueBuffer 59 60 ```go 61 // buffer.go 62 package main 63 64 import ( 65 "github.com/pharosnet/flyline" 66 "time" 67 "context" 68 ) 69 70 func main() { 71 buf := flyline.NewQueueBuffer() 72 buf.Send(time.Now()) 73 value, ok := buf.Recv() 74 recvTime := time.Time{} 75 flyline.ValueScan(value, &recvTime) 76 println(recvTime) 77 // close buffer 78 buf.Close() 79 // change ctx to timeout, if sync with timeout. 80 buf.Sync(context.Background()) 81 } 82 ``` 83 84 ```sh 85 $ go run buffer.go 86 ``` 87 88 Benchmarks 89 ---------------------------- 90 Each of the following benchmark tests sends an incrementing sequence message from one goroutine to another. The receiving goroutine asserts that the message is received is the expected incrementing sequence value. Any failures cause a panic. Unless otherwise noted, all tests were run using `GOMAXPROCS=2`. 91 92 ##### MacBook Pro 13" Retina, Mid 2015 93 94 * CPU: `Intel Core i5 @ 2.70 Ghz` 95 * Operation System: `OS X 10.13.4` 96 * Go Runtime: `Go 1.10.0` 97 * Go Architecture: `amd64` 98 99 Scenario | Per Operation Time 100 -------- | ------------------ 101 Channels: Buffered, Non-blocking, GOMAXPROCS=1| 19.7 ns/op 102 Channels: Buffered, Non-blocking, GOMAXPROCS=2| 21.0 ns/op 103 Channels: Buffered, Non-blocking, GOMAXPROCS=3, Contended Write | 110.0 ns/op 104 ArrayBuffer: Buffered, Non-blocking, GOMAXPROCS=1| 11.9 ns/op 105 ArrayBuffer: Buffered, Non-blocking, GOMAXPROCS=2| 7.14 ns/op 106 ArrayBuffer: Buffered, Non-blocking, GOMAXPROCS=3, Contended Write | 11.9 ns/op 107 108 ## Contact 109 110 Ryougi Nevermore [@ryougi](https://github.com/RyougiNevermore) 111 112 ## License 113 114 `flyline` source code is available under the GPL-3 [License](/LICENSE).