<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Network",
  "identifier" : "/documentation/Network/NetworkBrowser/run(_:)-31x4b",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Network"
    ],
    "preciseIdentifier" : "s:7Network0A7BrowserC3runyyySay8EndpointQzGYaYbKYAcYaKF"
  },
  "title" : "run(_:)"
}
-->

# run(_:)

Run the browser and receive updates when when the set of discovered
endpoints change.

```
final func run(_ handler: @escaping @isolated(any) @Sendable ([Provider.Endpoint]) async throws -> Void) async throws
```

## Parameters

`handler`

The closure to which discovered endpoints will be delivered.
Return `.continue` from this closure to continue browsing,
`finish(endpoints)` to return the discovered endpoints from
`run()`, and do not return anything to browse forever.

## Discussion

Starts the browser, which will cause the browser to begin browsing for
services on the network. A `stateUpdateHandler` may be used to determine
when the state changes. If the browser fails, the state will transition
to failed with an associated `NWError` value. Otherwise, the state will
transition to ready. A failed state will cause `run()` to throw an exception.

Return `.continue` from the closure passed to `run()` if the desired endpoints
have not been found to continue browsing.
Return `.finish(endpoints)` if the desired endpoints have been found. The
value associated with `.finish` will be returned from `run()`.
To browse forever, do not return any value from the closure.

`run()` should only be called once on a browser, and multiple calls to
`run()` will throw exceptions.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)