apr
Hello!
Is there a way to send a message to a Genserver process such that the message skips all other messages in the genserver’s message queue, and will be the next message to be processed?
Or would the solution involve using a custom queue in front of the genserver worker that exposes an API to achieve this?
Thanks!
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
I think I’ve found a small improvement I could contribute to <%= web_namespace %>.CoreComponents (installer/templates/phx_web/compo...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
cmkarlsson
You can use something called a
selective receive. The basic idea is to just pattern match on the priority message first and the rest of them later. There are some drawbacks doing this especially for large mailboxes. Also note, that you must do this in your own processes and can’t useGenServerbehaviour (as far as I know).Some links I found.
If you google for
selective receiveyou may found more information.An example:
apr
Thanks for the helpful links @cmkarlsson! I should have mentioned though that the process I was referring to was indeed a genserver
I will update my OP to reflect this.
jgonet
I dunno efficiency of this solution, but here’s idea: receive all messages and store it in priority queue, then process them one by one from this queue. Higher priority events will appear first to be processed.
apr
So you are suggesting the custom queue in front of the worker approach? I think that is probably the way to go. Are you aware of any good libraries that tackle this use case?
jgonet
Unfortunately, no. That was just abstract idea, but I’m sure there’s library for that.
apr
I couldn’t find any in particular, so I decided to use this: GitHub - discord/deque: Fast bounded deque using two rotating lists. · GitHub to simulate 3 queues with 3 priorities and store them in the GenServer’s state.
OvermindDL1
GenServer’s process in order, that is the purpose of their design.
There are alternative GenServer’s out in the erlang world (and thus useable via Elixir) that are Priority based genservers, so you can send messages and process them in different orders (first by priority then by received order).
apr
So @OvermindDL1, you’d consider managing priority state explicitly via queues stored in GenServer state bad practice? I want to use elixir modules as much as I can and managing priority manually doesn’t seem too hard.
NobbZ
Creating and managing a priority queue which you update on new messages is probably more expensive than just processing the messages in order.
peerreynders
http://www1.erlang.org/pipermail/erlang-questions/2005-October/017520.html
i.e.
A normal process can send messages to a GenServer - it would just mean that the priority management is in a separate process (which really shouldn’t be a big deal - Tasks for example are raw processes.) If the priority management process uses a blocking
call/3to the GenServer it wouldn’t select the next message from the process mailbox until thecallreturns.