🎭 To block or not to block, that is the question.

Let’s suppose we have a stream of events and a pull consumer. The consumer has two methods to fetch: the first is gonna block until it receives something, and the second has a timeout to unblock. My personal rule of thumb is:

- if you need to synchronously consume a single event then process it: use the blocking one, as you’re using the stream like a FIFO queue.
- if you need to fetch β€˜n’ events: use the non-blocking one, you might have no warranty that the stream contains (or is able to send) the expected amount of events.

0

If you have a fediverse account, you can quote this note from your own instance. Search https://mastodon.bsd.cafe/users/henomis/statuses/114196129423123011 on your instance and quote it. (Note that quoting is not supported in Mastodon.)