Skip to content

fix: Darwin services ordering in DiscoverServices#417

Merged
deadprogram merged 2 commits intotinygo-org:devfrom
acouvreur:fix-darwin-ordering
Mar 17, 2026
Merged

fix: Darwin services ordering in DiscoverServices#417
deadprogram merged 2 commits intotinygo-org:devfrom
acouvreur:fix-darwin-ordering

Conversation

@acouvreur
Copy link

The services will now appear on the expected order

Closes #416

Similar to #409 and its #410 pull request
Similar to #414 and its #415 pull request

The services will now appear on the expected order
@acouvreur
Copy link
Author

@deadprogram @jagobagascon review when you can please

Thanks a lot 👍

@jagobagascon I've pinged you even though you were only mentioned on Windows reviews, but the change is basically the same

Copy link
Member

@jagobagascon jagobagascon left a comment

Choose a reason for hiding this comment

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

LGTM

@acouvreur
Copy link
Author

@deadprogram can we merge this ?

Comment on lines 27 to +33
svcs := []DeviceService{}

if len(uuids) > 0 {
// The caller wants to get a list of services in a specific
// order.
svcs = make([]DeviceService, len(uuids))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be simplified:

Suggested change
svcs := []DeviceService{}
if len(uuids) > 0 {
// The caller wants to get a list of services in a specific
// order.
svcs = make([]DeviceService, len(uuids))
}
svcs := make([]DeviceService, len(uuids))

Copy link
Author

Choose a reason for hiding this comment

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

I've used the same "algorithm" that was already implemented in other OS specific.

Should we change it in this PR ?

Should we change all algorithms ?

Copy link
Member

Choose a reason for hiding this comment

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

I've used the same "algorithm" that was already implemented in other OS specific.

Should we change it in this PR ?

Should we change all algorithms ?

Perhaps we should look into seeing if we can use shared/improved code for all of them, but probably not in this PR.

Comment on lines +46 to 49
} else {
// The caller wants to get all services, in any order.
svcs = append(svcs, d.makeService(dsvcuuid, dsvc))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe move this case to the beginning of the loop for clarity

			if len(uuids) == 0 {
				// The caller wants to get all services, in any order.
				svcs = append(svcs, d.makeService(dsvcuuid, dsvc))
				continue
			}

found = true
break
// One of the services we're looking for.
svcs[j] = d.makeService(dsvcuuid, dsvc)
Copy link
Contributor

Choose a reason for hiding this comment

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

the loop should probably break as soon as the service uuid is found, but this raises the question if duplicate uuids are allowed in the input of the method (which documentation does not prevent and the code does not check for).

Copy link
Member

Choose a reason for hiding this comment

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

AFAIK duplicates should be allowed.

@deadprogram
Copy link
Member

Thank your for working on this one @acouvreur

@HattoriHanzo031 and @acouvreur perhaps working on a followup to standardize the ordering logic across all platforms would be a good thing!

Now squash/merging. Thanks again!

@deadprogram deadprogram merged commit 5c19f86 into tinygo-org:dev Mar 17, 2026
4 checks passed
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.

4 participants