Commit b51983a1 authored by Leo Iannacone's avatar Leo Iannacone

use a dictonary to handle with watchers on socket

parent c94025e4
...@@ -72,9 +72,13 @@ function __get_files_list(dir, onlyDirectories, callback) { ...@@ -72,9 +72,13 @@ function __get_files_list(dir, onlyDirectories, callback) {
} }
function __watch_path_onsocket(event_name, socket, data, watch_path, updater) { function __watch_path_onsocket(event_name, socket, data, watch_path, updater) {
name = "watcher-" + event_name socket.get("watchers", function(err, socket_watchers){
socket.get(name, function (err, watcher) { if (! socket_watchers) {
// init socket watchers
socket_watchers = {}
}
try { try {
var watcher = socket_watchers[event_name]
if (watcher) if (watcher)
watcher.close() watcher.close()
...@@ -95,14 +99,14 @@ function __watch_path_onsocket(event_name, socket, data, watch_path, updater) { ...@@ -95,14 +99,14 @@ function __watch_path_onsocket(event_name, socket, data, watch_path, updater) {
updater(event_name, socket, data) updater(event_name, socket, data)
}); });
} }
socket.set(name, watcher) socket_watchers[event_name] = watcher
socket.set("watchers", socket_watchers)
}) })
} catch (err) { } catch (err) {
__errors_handler("__watch_path_onsocket <- " + arguments.callee.caller.name, err, socket) __errors_handler("__watch_path_onsocket <- " + arguments.callee.caller.name, err, socket)
return return
} }
}) })
return true;
} }
function __generic_handler_watcher(event_name, socket, data, watch_path, callback) { function __generic_handler_watcher(event_name, socket, data, watch_path, callback) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment