Commit 0c12b7a0 authored by Jeromy's avatar Jeromy

move blocking calls out of single threaded loops, cancel contexts ASAP

parent 74d015bd
...@@ -187,9 +187,12 @@ func (ds *dagService) GetNodes(ctx context.Context, keys []u.Key) []NodeGetter { ...@@ -187,9 +187,12 @@ func (ds *dagService) GetNodes(ctx context.Context, keys []u.Key) []NodeGetter {
} }
go func() { go func() {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
blkchan := ds.Blocks.GetBlocks(ctx, keys) blkchan := ds.Blocks.GetBlocks(ctx, keys)
for { for count := 0; count < len(keys); {
select { select {
case blk, ok := <-blkchan: case blk, ok := <-blkchan:
if !ok { if !ok {
...@@ -205,6 +208,7 @@ func (ds *dagService) GetNodes(ctx context.Context, keys []u.Key) []NodeGetter { ...@@ -205,6 +208,7 @@ func (ds *dagService) GetNodes(ctx context.Context, keys []u.Key) []NodeGetter {
is := FindLinks(keys, blk.Key(), 0) is := FindLinks(keys, blk.Key(), 0)
for _, i := range is { for _, i := range is {
sendChans[i] <- nd sendChans[i] <- nd
count++
} }
case <-ctx.Done(): case <-ctx.Done():
return return
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment