Can I stream messages from GenServer or Task?

I want to spawn some short lived processes maybe GenServers or Tasks that dont hold any state and use them to listen for a few messages. When I receive then them, I want to decode them and validate them. The function used to start the process should return a stream containing the valid values. After a certain number number of valid values the process should shut down. How do I stream the messages from the process? Also would you use a GenServer or Task for this?



If we talk about short lived processes, then I would suggest to go for tasks.

But it sounds for me like a genserver (or agent), that uses a state? Because you want to stop everything after a certain amount of messages? Maybe you can give us more detailed clarification of what you want to do?