Skip to content

Commit 4881b69

Browse files
committed
Replace remaining usages of futures_executor::block_on with spawn_future
1 parent d4b8fe5 commit 4881b69

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

opentelemetry-sdk/src/metrics/periodic_reader.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,9 @@ impl MetricReader for PeriodicReader {
377377

378378
drop(inner); // don't hold lock when blocking on future
379379

380-
futures_executor::block_on(receiver)
381-
.map_err(|err| MetricsError::Other(err.to_string()))
382-
.and_then(|res| res)
380+
crate::util::spawn_future(receiver);
381+
382+
Ok(())
383383
}
384384

385385
fn shutdown(&self) -> Result<()> {
@@ -395,14 +395,22 @@ impl MetricReader for PeriodicReader {
395395
.map_err(|e| MetricsError::Other(e.to_string()))?;
396396
drop(inner); // don't hold lock when blocking on future
397397

398-
let shutdown_result = futures_executor::block_on(receiver)
399-
.map_err(|err| MetricsError::Other(err.to_string()))?;
400-
401-
// Acquire the lock again to set the shutdown flag
402-
let mut inner = self.inner.lock()?;
403-
inner.is_shutdown = true;
398+
let inner = self.inner.clone();
399+
crate::util::spawn_future(async move {
400+
match receiver
401+
.await
402+
.map_err(|err| MetricsError::Other(err.to_string()))
403+
{
404+
// Acquire the lock again to set the shutdown flag
405+
Ok(Ok(())) => match inner.lock() {
406+
Ok(mut inner) => inner.is_shutdown = true,
407+
Err(_poisoned) => {}
408+
},
409+
Err(err) | Ok(Err(err)) => global::handle_error(err),
410+
}
411+
});
404412

405-
shutdown_result
413+
Ok(())
406414
}
407415
}
408416

0 commit comments

Comments
 (0)