Open anacrolix opened 4 years ago
Hey, sorry for the delayed reply. Can you share some more of your code? I'm not sure this has to do directly with this crate but I can try and help debug it a bit.
I want to call Group::work
with an async
function. Something like g.work(async { ... }). I'm not sure how to bundle up an async function so that it can go into something expecting an Fn<()>
closure.
I could be wrong but I don't think you can construct asynchronous closures. It doesn't have anything to do with that trait.
On Sun, Feb 2, 2020 at 21:00 Matt Joiner notifications@github.com wrote:
I want to call Group::work with an async function. Something like g.work(async { ... }). I'm not sure how to bundle up an async function so that it can go into something expecting an Fn<()> closure.
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/gsquire/singleflight/issues/2?email_source=notifications&email_token=AAUKW5VPK4AFQHKGPK4J5YTRA6QHDA5CNFSM4KORQOHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKSP3QQ#issuecomment-581238210, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUKW5U3STAFNXEY5B74LRTRA6QHDANCNFSM4KORQOHA .
-- Sent from Gmail Mobile
Thanks, it does seem like async function traits are not yet available in the language. In the meanwhile, would it be appropriate to have a work
function that accepts a future?
I am going to have to think about it. I am worried that it would defeat the purpose of non-blocking functions if I mix in wait groups and locks. Because in my mind, if we acquire a lock for the group when work
is called we essentially block that thread from doing any execution if another thread holds that lock. So an async
function can't make progress. Does that make sense or am I not seeing this right?
I think it's okay to lock the Group
while checking for existing work, and marking that we're doing it, and then unlocking while the work is done. I have created my own Singleflight
in the meanwhile, that may serve as inspiration.
Nice, thanks for sharing. I don't know if I will be able to make a patch to add that any time soon but I will be happy to review a PR if you submit one.
How do I use this with
async
work
? I get something like the error