Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constructor: allow nil options #603

Merged
merged 1 commit into from
Apr 18, 2019
Merged

constructor: allow nil options #603

merged 1 commit into from
Apr 18, 2019

Conversation

Stebalien
Copy link
Member

This can make it significantly easier to configure libp2p with optional options.

@ghost ghost assigned Stebalien Apr 17, 2019
@ghost ghost added the status/in-progress In progress label Apr 17, 2019
@Stebalien Stebalien requested a review from vyzo April 17, 2019 23:36
@Stebalien Stebalien mentioned this pull request Apr 17, 2019
5 tasks
var optsRun []int
optcount := 0
newOpt := func() Option {
index := optcount
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: possibly remove the index assignment by incrementing optcount in a defer statement?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, wait, no. We need to capture the current value.

This can make it significantly easier to configure libp2p with optional options.
@Stebalien Stebalien merged commit 6a6b415 into master Apr 18, 2019
@ghost ghost removed the status/in-progress In progress label Apr 18, 2019
Copy link
Contributor

@bigs bigs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally lgtm, just some small feedback

if err := cfg.Apply(newOpt(), nil, ChainOptions(newOpt(), newOpt(), ChainOptions(), ChainOptions(nil, newOpt()))); err != nil {
t.Fatal(err)
}
if optcount != len(optsRun) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's compare against a constant here, i.e. 4

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM.

if optcount != len(optsRun) {
t.Errorf("expected to have handled %d options, handled %d", optcount, len(optsRun))
}
for i, x := range optsRun {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is meant to test ordering, definitely drop a comment so future programmers understand the behavior

@Stebalien Stebalien deleted the feat/nil-option branch April 18, 2019 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants