-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlimit.go
More file actions
43 lines (38 loc) · 677 Bytes
/
Copy pathlimit.go
File metadata and controls
43 lines (38 loc) · 677 Bytes
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
// Create by Yale 2019/3/19 9:28
package stream
type limit struct {
me *sinkNode
num uint64
cancelRequest bool
value []T
count int64
}
func (sk *limit)Begin(size int64) {
if sk.num == 0 {
sk.cancelRequest = true
}else{
sk.value = make([]T,0)
}
}
func (sk *limit)Accept(t T) {
sk.count++
if sk.count<=int64(sk.num) {
sk.value = append(sk.value,t)
}else{
sk.cancelRequest = true
}
}
func (sk *limit)End() {
next:=sk.me.next.value
next.Begin(int64(len(sk.value)))
for _,v:=range sk.value{
if next.CancellationRequested() {
break
}
next.Accept(v)
}
next.End()
}
func (sk *limit)CancellationRequested() bool {
return sk.cancelRequest
}