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-blockservice
Commits
686220bf
Commit
686220bf
authored
Jan 20, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract context func
@jbenet would like it to work this way
parent
4332ac4c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
8 deletions
+16
-8
worker/worker.go
worker/worker.go
+16
-8
No files found.
worker/worker.go
View file @
686220bf
...
...
@@ -117,14 +117,7 @@ func (w *Worker) start(c Config) {
// reads from |workerChan| until process closes
w
.
process
.
Go
(
func
(
proc
process
.
Process
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
// shuts down an in-progress HasBlock operation
proc
.
Go
(
func
(
proc
process
.
Process
)
{
<-
proc
.
Closing
()
cancel
()
})
ctx
:=
childContext
(
proc
)
// shut down in-progress HasBlock when time to die
limiter
:=
ratelimit
.
NewRateLimiter
(
proc
,
c
.
NumWorkers
)
for
{
select
{
...
...
@@ -169,3 +162,18 @@ func (s *BlockList) Pop() *blocks.Block {
func
(
s
*
BlockList
)
Len
()
int
{
return
s
.
list
.
Len
()
}
// TODO extract
type
waitable
interface
{
Closing
()
<-
chan
struct
{}
}
// TODO extract
func
childContext
(
w
waitable
)
context
.
Context
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
go
func
()
{
<-
w
.
Closing
()
cancel
()
}()
return
ctx
}
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