<html>Hello,<br /><br />I'm looking for advice about implementing a timer queue in erlang or elixir.<br /><br />Basically what I need is a queue where I can write a timestamp, a key, and a value. When the local time reaches the timestamp, I want to handle the key/value (I guess receiving a message with the key and fetch, or receiving the key/value).<br />The timer must be cancelable as the value is very small but will lead to heavy computation. I want to be able to fetch a key from outside of the process at any time and run the computation (and then cancel the scheduled computation).<br /><br />This is a subset of the `timer` module. But I need to persist the data to disk and reload on application start.<br /><br />I will have a tiny amount of entries : around 1000.<br /><br />At the moment I have an ordered_set with `{Timestamp, UserKey} = Key` as keys, I lookup for the first key and send_after to self the `Key` with `erlang:<span style="color: #333333;">start_timer</span><span style="color: #777777;">(</span><span style="color: #333333;">max</span><span style="color: #777777;">(TimeStamp</span><span style="color: #777777;">,</span><span style="color: #333333;"> </span><span style="color: #9c5d27;">1</span><span style="color: #777777;">),</span><span style="color: #333333;"> self</span><span style="color: #777777;">(),</span><span style="color: #333333;"> </span><span style="color: #777777;">{</span><span style="color: #9c5d27;">run_deletion</span><span style="color: #777777;">,</span><span style="color: #333333;"> Key</span><span style="color: #777777;">})</span>`, which returns a ref that I keep in state so I can ignore timer messages with an older ref. Everything is done inside a gen_server where I load the table from disk after init. Also I have to write the table to disk after each update because it is very important that all events are handled.<br /><br />I'm about to implement cancellation but the code becomes messy as I do both table management and data management in the same module.<br /><br />I wonder if there are implementations of this pattern in the community ? I could use a priority queue, but it seems to me that the implementations use a fixed list of priorities, and not arbitrary priorities (like a timestamp).<br /><br />Thank you</html>