hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

9.5K
active users

DiazCarrete

If I'm using "async" in Haskell to spawn a thread hackage.haskell.org/package/as and I want the thread to know about its own Async handle, which would be the best way of doing so?

It seems hat "fixIO" hackage.haskell.org/package/ba could do the trick, but I'm not sure if it would be a good idea 🤔

Example of where I used "fixIO" for that purpose: discourse.haskell.org/t/dynami

hackage.haskell.orgControl.Concurrent.Async

@DiazCarrete what would be the usecase? Mostly you can't do much with the Async itself, if that is what you mean by handle. But you can easily get the ThreadId (something like myThreadId or such)

@DiazCarrete thanks! Didn't read the linked to thing, and don't fully grasp the usecase, so with these in mind - globally limiting counts sound hard (not technically, bit in practical use).

When I'm concerned I use a pool that limits concurrency on a per-usecase (often practically per callsite) basis.

I have since custom light abstraction on that. Was not trivial to make all the masking right so accounting doesn't leak. Might want to publish one day..

@DiazCarrete I think my implementation is a wrapper around the respective ops, and indeed manages some mutable vars. But those are only about counts, not about Async identities. It also has some queueing/ rejection support for shedding.

@DiazCarrete my usecase only needs a horizontal limiting of runaway concurrency. Your nested withAsync case sounds like some recursive deep processing.. which might better need a case-specific structure. For example, use horizontal limiting on the concurrent top level tasks, but then for each task do something specific to limit concurrency.. like pass along depth in recursion and don't go concurrent below certain depth of such