_sync vs _async and Drop with HashMap
#204
-
|
The documentation is somewhat vague about the implications of mixing I have a case where I want to keep an object in a map throughout some scope, using a guard type that removes the item from the map in Drop, but obviously you can't Something like (with the scopeguard if hash_map.insert_async(request_id, ()).await.is_err() { todo!() }
{
defer! {
hash_map.remove_sync(request_id);
}
// ... long async operations ...
} // exit scope, remove from map.That case is trivial to rewrite with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
That's true for those that only provide synchronous methods, e.g., Therefore, I'd suggest that you make |
Beta Was this translation helpful? Give feedback.
That's true for those that only provide synchronous methods, e.g.,
DashMaporparking_lot.sccis different; its internal locks can be acquired either synchronously or asynchronously. The detailed scenario is described in thesaadoc; in short, there is no guarantee that the lock owner task gets scheduled by the asynchronous runtime in case another task is blocking the executor.-> Calling
_syncmethods when dropping aFutureis still bad; cancelledFutures are dropped within an asynchronous executor.Therefore, I'd suggest that you make
_synccalls in a separate thread or a th…