Hacker News new | ask | show | jobs
by amarkov 3018 days ago
Futures aren't a natural way to formulate many important concurrency problems. If I want a thread polling an external system and putting records in a work queue for as long as my application is running... well, what's that a future of?
2 comments

That's what thread pools are for. They have a work queue you fill and workers depop it. Literally 5 lines in python and i imagine most modern languages.
Right, but thread pools are simple because they don't offer any sort of API for the tasks in the work queue. You're just writing arbitrary code. So rather than reasoning about an abstract execution model, you have to carefully think about every line to make sure you don't accidentally share mutable state.
In Java with Spring you'd do something like:

@Scheduled(fixedRate = 5000) public void poll() { getCrapAndPutOnConsumerQueue(); }