acw / rate-limit

A basic rate-limiting library for Haskell
BSD 3-Clause "New" or "Revised" License
21 stars 4 forks source link

Generalize the types #5

Open Helkafen opened 5 years ago

Helkafen commented 5 years ago

Thanks for rate-limit and for the good documentation. One suggestion: it would be nice to generalize over the monad type. For instance, to make it straightforward to use with the lifted version of mapConcurrently in lifted-async :

My specific use case was related to a switch from IO to ExceptT e IO.

Cheers!

acw commented 5 years ago

Interesting idea. Playing around, I think there's two problems with a lightweight solution: one that's mostly annoying, and one that highlights a weakness in the library that I've mostly tried to ignore.

(1) I could probably create mirrored versions of the existing calls, but using MonadIO type constraints, but only if I also took in an executor of type MonadIO m => m a -> IO a. This is because there's some threading going on under the hood, and so I'd need to replicate the monadic environment in a new thread. Which leads to ...

(2) Right now, if your rate-limited action throws an exception, weird things will happen. Like, I think the whole thing might block forever? In your ExceptT example, a similar thing would happen: the exception within the rate-limited action will be lost. So ... that's probably not what you want?

The right thing to do would be something a bit more structural, which is likely more than I'm going to do on this library. As you can see from the history, this project isn't super active. That being said, I'm always excited to find new maintainers ...