Find Related products on Amazon

Shop on Amazon

The Scalar Select Anti-Pattern

Published on: 2025-07-06 13:19:23

Scalar Select Anti-Pattern I’ve written a number of stateful services starting with an event loop at the core: async for event in events_incoming: await process(event) I had to refactor this loop later, every time. For an example, see the direct cause for the article, this TigerBeetle PR. Let me write the refactoring down, so that I get it right from the get go next time! Scalar Select Let’s say I am implementing an LSP server for some programming language. There’s going to be three main sources of events: file modifications from user typing code in or git operations, requests from the client (“give me completions!”), output from compilation jobs running in the background with error messages and such. The “obvious” event loop setup for this case looks like this: events_incoming: Stream[Event] = merge( events_file_system, events_compiler, events_lsp, ) async for event in events_incoming: await process(event) Here, merge is an operator that takes a number of event streams, and merg ... Read full article.