mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 13:25:00 +00:00
Simplify OnceMap::wait_blocking
(#4704)
## Summary De-duplicate by calling directly into the async version.
This commit is contained in:
parent
f3d1e52e65
commit
ea031461c5
1 changed files with 1 additions and 24 deletions
|
@ -77,30 +77,7 @@ impl<K: Eq + Hash, V: Clone, H: BuildHasher + Clone> OnceMap<K, V, H> {
|
||||||
///
|
///
|
||||||
/// Will hang if [`OnceMap::done`] isn't called for this key.
|
/// Will hang if [`OnceMap::done`] isn't called for this key.
|
||||||
pub fn wait_blocking(&self, key: &K) -> Option<V> {
|
pub fn wait_blocking(&self, key: &K) -> Option<V> {
|
||||||
let notify = {
|
futures::executor::block_on(self.wait(key))
|
||||||
let entry = self.items.get(key)?;
|
|
||||||
match entry.value() {
|
|
||||||
Value::Filled(value) => return Some(value.clone()),
|
|
||||||
Value::Waiting(notify) => notify.clone(),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Register the waiter for calls to `notify_waiters`.
|
|
||||||
let notification = pin!(notify.notified());
|
|
||||||
|
|
||||||
// Make sure the value wasn't inserted in-between us checking the map and registering the waiter.
|
|
||||||
if let Value::Filled(value) = self.items.get(key).expect("map is append-only").value() {
|
|
||||||
return Some(value.clone());
|
|
||||||
};
|
|
||||||
|
|
||||||
// Wait until the value is inserted.
|
|
||||||
futures::executor::block_on(notification);
|
|
||||||
|
|
||||||
let entry = self.items.get(key).expect("map is append-only");
|
|
||||||
match entry.value() {
|
|
||||||
Value::Filled(value) => Some(value.clone()),
|
|
||||||
Value::Waiting(_) => unreachable!("notify was called"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the result of a previous job, if any.
|
/// Return the result of a previous job, if any.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue