Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
logana
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘旋尧
logana
Commits
d20a0188
Commit
d20a0188
authored
Nov 13, 2017
by
usual2970
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
5000dbff
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
7 deletions
+12
-7
collect.go
collect/collect.go
+11
-6
collect_test.go
collect/collect_test.go
+1
-1
No files found.
collect/collect.go
View file @
d20a0188
...
@@ -41,6 +41,7 @@ type Collect struct {
...
@@ -41,6 +41,7 @@ type Collect struct {
wg
WaitGroupWrap
wg
WaitGroupWrap
chanPool
chan
bool
chanPool
chan
bool
chanItem
chan
*
Item
chanItem
chan
*
Item
f
*
os
.
File
}
}
func
NewCollect
(
filePath
string
,
needUnzip
bool
)
*
Collect
{
func
NewCollect
(
filePath
string
,
needUnzip
bool
)
*
Collect
{
...
@@ -69,8 +70,8 @@ func (c *Collect) GetItems() error {
...
@@ -69,8 +70,8 @@ func (c *Collect) GetItems() error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
defer
f
.
Close
()
c
.
f
=
f
rd
:=
bufio
.
NewReader
(
f
)
rd
:=
bufio
.
NewReader
(
c
.
f
)
c
.
wg
.
Wrap
(
func
()
{
c
.
wg
.
Wrap
(
func
()
{
for
{
for
{
...
@@ -90,7 +91,7 @@ func (c *Collect) GetItems() error {
...
@@ -90,7 +91,7 @@ func (c *Collect) GetItems() error {
}
}
})
})
c
.
wg
.
Wrap
(
func
()
{
for
{
for
{
select
{
select
{
case
item
:=
<-
c
.
chanItem
:
case
item
:=
<-
c
.
chanItem
:
...
@@ -101,11 +102,10 @@ func (c *Collect) GetItems() error {
...
@@ -101,11 +102,10 @@ func (c *Collect) GetItems() error {
})
})
case
<-
time
.
After
(
30
*
time
.
Second
)
:
case
<-
time
.
After
(
30
*
time
.
Second
)
:
log
.
Printf
(
"timed out"
)
//等待30后退出
log
.
Printf
(
"timed out"
)
//等待30后退出
break
return
}
}
}
}
})
return
nil
return
nil
}
}
...
@@ -152,5 +152,10 @@ func (c *Collect) handleItem(item *Item) {
...
@@ -152,5 +152,10 @@ func (c *Collect) handleItem(item *Item) {
}
}
func
(
c
*
Collect
)
Exit
()
{
func
(
c
*
Collect
)
Exit
()
{
c
.
wg
.
Wait
()
c
.
wg
.
Wait
()
if
c
.
f
!=
nil
{
c
.
f
.
Close
()
}
}
}
collect/collect_test.go
View file @
d20a0188
...
@@ -22,7 +22,7 @@ func TestOnItem(t *testing.T) {
...
@@ -22,7 +22,7 @@ func TestOnItem(t *testing.T) {
})
})
err
:=
c
.
GetItems
()
err
:=
c
.
GetItems
()
c
.
Exit
()
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
c
.
Exit
()
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment