-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.go
58 lines (43 loc) · 2.19 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
Package multicast provides a Chan type that can multicast and replay messages to
multiple receivers.
Multicast and Replay
Native Go channels don't support multicasting the same message to multiple
receivers and they don't support replaying previously sent messages.
Unlike native Go channels, messages send to this channel are multicast to
all receiving endpoints. A new endpoint created while the channel is operational
can choose to receive messages previously sent by specifying a replay count
parameter, or 0 to indicate it is only interested in new messages.
You can also limit playback to messages younger than a certain age because
the channel stores a timestamp with each message you send to it.
Just like native Go channels, the channel exhibits blocking backpressure to
the sender goroutines when the channel buffer is full. Total speed of the
channel is dictated by the slowest receiver.
Lock and Goroutine free
This multicast channel is different from other multicast implementations in
that it uses only fast synchronization primitives like atomic operations to
implement its features. Furthermore, it also doesn't use goroutines internally.
This implementation is low-latency and has a high throughput.
If you are in a situation where you need to record and replay a stream
of data or you need to split a stream of data into multiple identical streams,
then this package offers a fast and simple solution.
Heterogeneous
Heterogeneous simply means that you can mix types, that is very convenient but
not typesafe. The Chan type provided in this package supports sending and
receiving values of mixed type:
ch := NewChan(128, 1)
ch.Send("hello")
ch.Send(42)
ch.Send(1.6180)
ch.Close(nil)
Regenerating this Package
The implementation in this package is generated from a generic implementation
of the Chan type found in the subdirectory "generic" inside this package. By
replacing the place-holder type with "interface{}" a heterogeneous Chan type
is created. To regenerate this channel implementation, run jig inside this
package directory:
go get -d github.com/reactivego/generics/cmd/jig
go run github.com/reactivego/generics/cmd/jig -v
*/
package multicast
import _ "github.com/reactivego/multicast/generic"