async-lock icon indicating copy to clipboard operation
async-lock copied to clipboard

Feature request: poll_lock(cx) for Mutex

Open black-binary opened this issue 5 years ago • 1 comments

I want to lock a Mutex<T> in my poll_read method but it seems like that there is no way to lock and wait for a Mutex in a non-async function. My workaround is creating an async closure and getting it boxed and pinned, storing it somewhere else, and then polling it, which is really annoying and inefficient.

https://github.com/black-binary/ap-kcp/blob/6bf035ea0349165094bf44e13ff4b09cb2bf66ab/src/async_kcp.rs#L54-L67

I think it would be nice if there are some methods like poll_lock(cx).

black-binary avatar Dec 04 '20 09:12 black-binary

I'd accept a PR for this method :)

ghost avatar Dec 06 '20 16:12 ghost

I think a better way of doing this would be like in smol-rs/async-channel#33, where we have a manual Future implementation for the locking functions. This is basically what the PR (#5) does anyways, and we could probably make it more generic.

notgull avatar Dec 15 '22 02:12 notgull