Rate limiting - leonoel/missionary GitHub Wiki

Bounded blocking execution

When using (via blk ,,,) It's important to remember that the blocking thread pool is unbounded, which can potentially lead to out-of-memory exceptions.

A simple way to work around it is by using a semaphore to rate limit the execution:

(def blocking-task (m/via m/blk blocking-fn))

(def sem (m/sem 10))

(def limited-task (m/sp (m/holding sem (m/? blocking-task))))

Keep in mind the semaphore should be created outside the sp block