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
58b9745f
Commit
58b9745f
authored
Nov 20, 2014
by
Brian Tiger Chow
Committed by
Jeromy
Dec 05, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(bitswap) group the deferreds
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
parent
26e6f28e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
4 deletions
+10
-4
bitswap.go
bitswap.go
+10
-4
No files found.
bitswap.go
View file @
58b9745f
...
@@ -92,11 +92,14 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err
...
@@ -92,11 +92,14 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err
// functions. This is difficult to enforce. May this comment keep you safe.
// functions. This is difficult to enforce. May this comment keep you safe.
ctx
,
cancelFunc
:=
context
.
WithCancel
(
parent
)
ctx
,
cancelFunc
:=
context
.
WithCancel
(
parent
)
defer
cancelFunc
()
ctx
=
eventlog
.
ContextWithMetadata
(
ctx
,
eventlog
.
Uuid
(
"GetBlockRequest"
))
ctx
=
eventlog
.
ContextWithMetadata
(
ctx
,
eventlog
.
Uuid
(
"GetBlockRequest"
))
log
.
Event
(
ctx
,
"GetBlockRequestBegin"
,
&
k
)
log
.
Event
(
ctx
,
"GetBlockRequestBegin"
,
&
k
)
defer
log
.
Event
(
ctx
,
"GetBlockRequestEnd"
,
&
k
)
defer
func
()
{
cancelFunc
()
log
.
Event
(
ctx
,
"GetBlockRequestEnd"
,
&
k
)
}()
promise
,
err
:=
bs
.
GetBlocks
(
parent
,
[]
u
.
Key
{
k
})
promise
,
err
:=
bs
.
GetBlocks
(
parent
,
[]
u
.
Key
{
k
})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -109,6 +112,7 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err
...
@@ -109,6 +112,7 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err
case
<-
parent
.
Done
()
:
case
<-
parent
.
Done
()
:
return
nil
,
parent
.
Err
()
return
nil
,
parent
.
Err
()
}
}
}
}
// GetBlocks returns a channel where the caller may receive blocks that
// GetBlocks returns a channel where the caller may receive blocks that
...
@@ -172,13 +176,15 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
...
@@ -172,13 +176,15 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
func
(
bs
*
bitswap
)
loop
(
parent
context
.
Context
)
{
func
(
bs
*
bitswap
)
loop
(
parent
context
.
Context
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
parent
)
ctx
,
cancel
:=
context
.
WithCancel
(
parent
)
defer
cancel
()
// signal termination
// Every so often, we should resend out our current want list
// Every so often, we should resend out our current want list
rebroadcastTime
:=
time
.
Second
*
5
rebroadcastTime
:=
time
.
Second
*
5
broadcastSignal
:=
time
.
NewTicker
(
bs
.
strategy
.
GetRebroadcastDelay
())
broadcastSignal
:=
time
.
NewTicker
(
bs
.
strategy
.
GetRebroadcastDelay
())
defer
broadcastSignal
.
Stop
()
defer
func
()
{
cancel
()
// signal to derived async functions
broadcastSignal
.
Stop
()
}()
for
{
for
{
select
{
select
{
...
...
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