Skip to content

Commit

Permalink
Merge pull request #25 from libp2p/feat/options
Browse files Browse the repository at this point in the history
More consistent use of options
  • Loading branch information
vyzo authored May 17, 2019
2 parents 257cea0 + c36fd0f commit bf6bb15
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions p2p/discovery/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
var log = logging.Logger("discovery")

// FindPeers is a utility function that synchonously collects peers from a Discoverer
func FindPeers(ctx context.Context, d Discoverer, ns string, limit int) ([]pstore.PeerInfo, error) {
res := make([]pstore.PeerInfo, 0, limit)
func FindPeers(ctx context.Context, d Discoverer, ns string, opts ...Option) ([]pstore.PeerInfo, error) {
var res []pstore.PeerInfo

ch, err := d.FindPeers(ctx, ns, Limit(limit))
ch, err := d.FindPeers(ctx, ns, opts...)
if err != nil {
return nil, err
}
Expand All @@ -27,10 +27,10 @@ func FindPeers(ctx context.Context, d Discoverer, ns string, limit int) ([]pstor
}

// Advertise is a utility function that persistently advertises a service through an Advertiser
func Advertise(ctx context.Context, a Advertiser, ns string) {
func Advertise(ctx context.Context, a Advertiser, ns string, opts ...Option) {
go func() {
for {
ttl, err := a.Advertise(ctx, ns)
ttl, err := a.Advertise(ctx, ns, opts...)
if err != nil {
log.Debugf("Error advertising %s: %s", ns, err.Error())
if ctx.Err() != nil {
Expand Down

0 comments on commit bf6bb15

Please sign in to comment.