Skip to content

Commit 520890c

Browse files
committed
refactor
1 parent 77aa3eb commit 520890c

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

1-producer-consumer/main.go

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ func main() {
6666
stream := GetMockStream()
6767

6868
// use a chan for producer to add tweet to it and consumer to consume from
69-
7069
tweetChan := make(chan *Tweet)
7170

7271
// Producer

1-producer-consumer/mockstream.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,28 @@ import (
1212
"time"
1313
)
1414

15-
// GetMockStream is a blackbox function which returns a mock stream for
16-
// demonstration purposes
17-
func GetMockStream() Stream {
18-
return Stream{0, mockdata}
15+
// ErrEOF returns on End of File error
16+
var ErrEOF = errors.New("End of File")
17+
18+
type Streaming interface{
19+
Next() (*Tweet, error)
1920
}
2021

22+
var _ Streaming = (*Stream)(nil)
23+
24+
2125
// Stream is a mock stream for demonstration purposes, not threadsafe
2226
type Stream struct {
2327
pos int
2428
tweets []Tweet
2529
}
2630

27-
// ErrEOF returns on End of File error
28-
var ErrEOF = errors.New("End of File")
31+
// GetMockStream is a blackbox function which returns a mock stream for
32+
// demonstration purposes
33+
func GetMockStream() Stream {
34+
return Stream{0, mockdata}
35+
}
36+
2937

3038
// Next returns the next Tweet in the stream, returns EOF error if
3139
// there are no more tweets

0 commit comments

Comments
 (0)