aboutsummaryrefslogtreecommitdiffstats
path: root/util/events.lua
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2010-09-17 04:09:59 +0500
committerWaqas Hussain <waqas20@gmail.com>2010-09-17 04:09:59 +0500
commit191c3849e27a658df2d21efe581d22a9db6623f6 (patch)
tree24717326ba0211d3598539f0ef1d519f100fae66 /util/events.lua
parent6f95b4de939b39798dfce8a779f31e6b7d71057a (diff)
downloadprosody-191c3849e27a658df2d21efe581d22a9db6623f6.tar.gz
prosody-191c3849e27a658df2d21efe581d22a9db6623f6.zip
util.events: Create new index on handler change instead of modifying existing one (this makes util.events fully reentrant).
Diffstat (limited to 'util/events.lua')
-rw-r--r--util/events.lua6
1 files changed, 2 insertions, 4 deletions
diff --git a/util/events.lua b/util/events.lua
index a1da4d8a..81bea639 100644
--- a/util/events.lua
+++ b/util/events.lua
@@ -18,14 +18,12 @@ function new()
local event_map = {};
local function _rebuild_index(event) -- TODO optimize index rebuilding
local _handlers = event_map[event];
- local index = handlers[event];
- if index then
- for i=#index,1,-1 do index[i] = nil; end
- else index = {}; handlers[event] = index; end
+ local index = {};
for handler in pairs(_handlers) do
t_insert(index, handler);
end
t_sort(index, function(a, b) return _handlers[a] > _handlers[b]; end);
+ handlers[event] = index;
end;
local function add_handler(event, handler, priority)
local map = event_map[event];