Why Nostr? What is Njump?
2025-04-13 10:27:57

mleku on Nostr: gawd, this subscription listener thing in this code is so written wrong firstly, it ...

gawd, this subscription listener thing in this code is so written wrong

firstly, it is using maps, which means mutexes, those aren't necessary for reading, and the actual websockets that are part of the map... have their own mutex on their functions so there is actually no need for this

so after fighting with this for the last day, i'm just gonna refactor this progressively

first is removing those maps and mutexes, that are unnecessary

they are just a lazy way to deal with removing elements of an array, but in Go that laziness means mutexes and it means less efficient concurrency, the array can be concurrently read, this is not a problem!

then once i have converted the lists of subscribers and their contained subscription IDs i can then make the structure common with the http except with the difference of a second interface that handles accessing the actual socket and id of each of the elements, which doesn't need to be done for the http one because it only does one filter one request

the last part is that the websocket has a context that closes same as the http.Request, so i will probably want to unify that somehow

this architecture is ugly, really ugly, like a classic bulgarian commieblock
Author Public Key
npub1fjqqy4a93z5zsjwsfxqhc2764kvykfdyttvldkkkdera8dr78vhsmmleku