Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Force processing of context cancellation first
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahhoward committed Oct 18, 2018
1 parent 9324d74 commit 6ec34f8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions hamt/hamt.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,15 @@ func makeAsyncTrieGetLinks(dagService ipld.DAGService, linkResults chan<- format
}

func emitResult(ctx context.Context, linkResults chan<- format.LinkResult, r format.LinkResult) {
// make sure that context cancel is processed first
// the reason is due to the concurrency of EnumerateChildrenAsync
// it's possible for EnumLinksAsync to complete and close the linkResults
// channel before this code runs
select {
case <-ctx.Done():
return
default:
}
select {
case linkResults <- r:
case <-ctx.Done():
Expand Down

0 comments on commit 6ec34f8

Please sign in to comment.