Created
September 19, 2023 12:14
-
-
Save AryanGodara/0b9767dc3c2838fb15d7a199a99ec7e4 to your computer and use it in GitHub Desktop.
Implementation of the topicFilter module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TOPIC_FILTER = struct | |
(* module TOPICFILTER : TOPIC_FILTER = struct *) | |
module UnixSocketMap = Map.Make (String) | |
let socketMap = ref UnixSocketMap.empty | |
let addSocket topic socket = | |
print_endline "Adding socket to topic"; | |
let sockets = | |
try UnixSocketMap.find topic !socketMap with Not_found -> [] | |
in | |
socketMap := | |
UnixSocketMap.add topic (List.append sockets [ socket ]) !socketMap | |
let removeSocket topic socket = | |
let sockets = | |
try UnixSocketMap.find topic !socketMap with Not_found -> [] | |
in | |
let sockets' = List.filter (fun s -> s <> socket) sockets in | |
socketMap := UnixSocketMap.add topic sockets' !socketMap | |
let getSockets topic = | |
let sockets = | |
try UnixSocketMap.find topic !socketMap with Not_found -> [] | |
in | |
List.rev sockets | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment