Async - Polysemy

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Edward Yang

Does polysemy's async from the Polysemy.Async package have the same gotchas as its equivalent in the async package itself?
The async package recommends to use withAsync to avoid thread leaks. Would this be a problem with polysemy's async function?

Edward Yang

What's the main issues using withLowerToIO? I understand most of the polysemy team doesn't like this, and is removed in the v2 draft (as explained by googleson).
I don't doubt the team's decision on this, I simply want to understand what problems came with using the forklift effect.

I'm working on a backend server where I'm dealing with thread leaks after introducing withAsync to it.
Since I'm not sure what else to do, I tried using withLowerToIO and withAsync from the async package itself.
This cancels the threads properly now, but is there any obvious gotchas? This is my reason for asking about the issues that come with using withLowerToIO.
I'm using this as a band-aid solution for now until a proper fix comes out. Looking forward to your thoughts!

Edit: Nevermind looks like I'm already seeing another issue pop-up. Still interested in why withLowerToIO is bad, other than it using an extra thread

Sandy Maguire

withLowerToIO depends on a global thread that is guaranteed to never be locked, which isn't an invariant we can enforce :)

Torsten Schmits

ugh concurrency with effects is so hacky

Georgi Lyubenov // googleson78

I guess that's the result of not having(?) the ability to express thread communication in the type system

Georgi Lyubenov // googleson78

but maybe I'm just not familiar enough with the topic

Torsten Schmits

yeah that would be nice

TheMatten

I think the answer usually isn't that you can't represent it using types, but that it would be ugly
Yesterday we ended up talking with Love about how delimited continuations could possibly be made safe in context of effect system with lowering as long as their scope was tracked and lowering would require passed in operation to be polymorphic over scope - basically, ST monad trick on steroids
I guess you could similarly parameterize your monad (or part of your effect stack) over scope of surrounding async call and provide it with scoped handles for sending messages to threads
But it would be bunch of additional type parameters to track

Edward Yang

Does polysemy have a version of sequenceConcurrently that lets you control the max # of threads?
Edit: Found this thread https://github.com/polysemy-research/polysemy/issues/73