RooSoft
Keep a list of connection pids, with urls as keys
I am keeping connections to a list of servers represented by URLs. Each of them has a pid if connected.
Ideally, I’d like to have a simple list only containing the connected ones. It should also be possible to index by by URL to get a specific pid. Should also be easily updatable…
Been trying a keyword list such as
["google.com": #PID<0.109.0>]
But Keyword.get only accepts atoms as a key to get the pid, so, I am a bit confused as to if it’s the way to go or not… is there a better way to get this to work?
Most Liked
al2o3cr
Small callout - the : here makes the thing on the left side an atom, so this written without the keyword list sugar is:
[{:"google.com", pid}]
You likely don’t want hostnames turning into atoms, since atoms stick around forever.
The simplest alternative would be a Map, %{"google.com" => pid}
gpopides
Maybe you are looking for Map?
Keys can be either atoms or strings and to get the pids you use Map.values/1
And you can take the pid of a url using either map.key or Map.get(key)







