-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add DoNotWaitForStreamingResponses to ParallelRouter
- Loading branch information
Showing
6 changed files
with
147 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package routinghelpers | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ipfs/go-cid" | ||
"github.com/libp2p/go-libp2p/core/peer" | ||
"github.com/libp2p/go-libp2p/core/routing" | ||
) | ||
|
||
// nothing is like [Null] but it never reach quorum for streaming responses. | ||
type nothing struct { | ||
Null | ||
} | ||
|
||
// SearchValue always returns ErrNotFound | ||
func (nr nothing) SearchValue(ctx context.Context, _ string, _ ...routing.Option) (<-chan []byte, error) { | ||
return makeChannelThatDoNothingAndIsClosedOnCancel[[]byte](ctx), nil | ||
} | ||
|
||
// FindProvidersAsync always returns a closed channel | ||
func (nr nothing) FindProvidersAsync(ctx context.Context, _ cid.Cid, _ int) <-chan peer.AddrInfo { | ||
return makeChannelThatDoNothingAndIsClosedOnCancel[peer.AddrInfo](ctx) | ||
} | ||
|
||
func makeChannelThatDoNothingAndIsClosedOnCancel[T any](ctx context.Context) <-chan T { | ||
ch := make(chan T) | ||
go func() { | ||
<-ctx.Done() | ||
close(ch) | ||
}() | ||
return ch | ||
} | ||
|
||
var _ routing.Routing = nothing{} |