Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-bitswap
Commits
c3ce1319
Commit
c3ce1319
authored
Mar 05, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify provideCollector
parent
6e6c6638
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
22 deletions
+9
-22
workers.go
workers.go
+9
-22
No files found.
workers.go
View file @
c3ce1319
...
...
@@ -83,17 +83,7 @@ func (bs *Bitswap) provideCollector(ctx context.Context) {
defer
close
(
bs
.
provideKeys
)
var
toprovide
[]
u
.
Key
var
nextKey
u
.
Key
select
{
case
blk
,
ok
:=
<-
bs
.
newBlocks
:
if
!
ok
{
log
.
Debug
(
"newBlocks channel closed"
)
return
}
nextKey
=
blk
.
Key
()
case
<-
ctx
.
Done
()
:
return
}
var
keysOut
chan
u
.
Key
for
{
select
{
...
...
@@ -102,21 +92,18 @@ func (bs *Bitswap) provideCollector(ctx context.Context) {
log
.
Debug
(
"newBlocks channel closed"
)
return
}
toprovide
=
append
(
toprovide
,
blk
.
Key
())
case
bs
.
provideKeys
<-
nextKey
:
if
keysOut
==
nil
{
nextKey
=
blk
.
Key
()
keysOut
=
bs
.
provideKeys
}
else
{
toprovide
=
append
(
toprovide
,
blk
.
Key
())
}
case
keysOut
<-
nextKey
:
if
len
(
toprovide
)
>
0
{
nextKey
=
toprovide
[
0
]
toprovide
=
toprovide
[
1
:
]
}
else
{
select
{
case
blk
,
ok
:=
<-
bs
.
newBlocks
:
if
!
ok
{
return
}
nextKey
=
blk
.
Key
()
case
<-
ctx
.
Done
()
:
return
}
keysOut
=
nil
}
case
<-
ctx
.
Done
()
:
return
...
...
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