(
udid: &str,
http_origin: Option<&str>,
)
| 100 | } |
| 101 | |
| 102 | pub async fn discover_targets( |
| 103 | udid: &str, |
| 104 | http_origin: Option<&str>, |
| 105 | ) -> Result<WebKitTargetDiscovery, AppError> { |
| 106 | let monitor = webkit_discovery_monitor(udid); |
| 107 | monitor.clone().ensure_started(); |
| 108 | |
| 109 | let deadline = Instant::now() + WEBKIT_DISCOVERY_TIMEOUT; |
| 110 | loop { |
| 111 | let discovery = monitor.discovery(http_origin).await; |
| 112 | if !discovery.targets.is_empty() || Instant::now() >= deadline { |
| 113 | return Ok(discovery); |
| 114 | } |
| 115 | |
| 116 | let Some(remaining) = deadline.checked_duration_since(Instant::now()) else { |
| 117 | return Ok(discovery); |
| 118 | }; |
| 119 | if timeout( |
| 120 | remaining.min(Duration::from_millis(250)), |
| 121 | monitor.notify.notified(), |
| 122 | ) |
| 123 | .await |
| 124 | .is_err() |
| 125 | { |
| 126 | continue; |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | fn webkit_discovery_monitor(udid: &str) -> Arc<WebKitDiscoveryMonitor> { |
| 132 | let monitors = WEBKIT_DISCOVERY_MONITORS.get_or_init(|| Mutex::new(HashMap::new())); |
nothing calls this directly
no test coverage detected