forked from Jorropo/channel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readonly.go
79 lines (63 loc) · 1.85 KB
/
readonly.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package channel
import "context"
// ReadOnly is a read-only channel wrapper offering improvements over a normal go channel.
type ReadOnly[T any] struct {
_ uncomparable
c *C[T]
}
// Read is the same C.Read
func (c ReadOnly[T]) Read() (T, error) {
return c.c.Read()
}
// ReadContext is the same as C.ReadContext
func (c ReadOnly[T]) ReadContext(ctx context.Context) (T, error) {
return c.c.ReadContext(ctx)
}
// ReadChannel is the same as C.ReadChannel
func (c ReadOnly[T]) ReadChannel() <-chan T {
return c.c.ReadChannel()
}
// Range is the same as C.Range
func (c ReadOnly[T]) Range(fn func(T) error) error {
return c.c.Range(fn)
}
// RangeContext is the same as C.RangeContext
func (c ReadOnly[T]) RangeContext(ctx context.Context, fn func(T) error) error {
return c.c.RangeContext(ctx, fn)
}
// Rest is the same as C.Rest
func (c ReadOnly[T]) Rest() ([]T, error) {
return c.c.Rest()
}
// RestContext is the same as C.RestContext
func (c ReadOnly[T]) RestContext(ctx context.Context) ([]T, error) {
return c.c.RestContext(ctx)
}
// Intercept is the same as C.Intercept, but return a ReadOnly.
func (c ReadOnly[T]) Intercept(fn func(T) error) ReadOnly[T] {
return c.c.Intercept(fn).ReadOnly()
}
// InterceptContext is the same as C.InterceptContext, but return a ReadOnly.
func (c ReadOnly[T]) InterceptContext(ctx context.Context, fn func(T) error) ReadOnly[T] {
return c.c.InterceptContext(ctx, fn).ReadOnly()
}
// Drain is the same as C.Drain
func (c ReadOnly[T]) Drain() {
c.c.Drain()
}
// DrainContext is the same as C.DrainContext
func (c ReadOnly[T]) DrainContext(ctx context.Context) {
c.c.DrainContext(ctx)
}
// Len is the same as C.Len
func (c ReadOnly[T]) Len() int {
return c.c.Len()
}
// Cap is the same as C.Cap
func (c ReadOnly[T]) Cap() int {
return c.c.Cap()
}
// Err is the same as C.Err
func (c ReadOnly[T]) Err() error {
return c.c.Err()
}