Diff

net/server_event.lua @ 6481:dbc72cd1332e

Move timer code out of util.timer and into relevant net.server backends
author daurnimator <quae@daurnimator.com>
date Mon, 20 Oct 2014 16:13:24 -0400
parent 6383:ec8878113907
child 6791:e813e8cf6046
line wrap: on
line diff
--- a/net/server_event.lua	Fri Oct 17 17:30:21 2014 -0400
+++ b/net/server_event.lua	Mon Oct 20 16:13:24 2014 -0400
@@ -848,6 +848,23 @@
 	sender:set_mode("*a");
 end
 
+local add_task do
+	local EVENT_LEAVE = (event.core and event.core.LEAVE) or -1;
+	local socket_gettime = socket.gettime
+	function add_task(delay, callback)
+		local event_handle;
+		event_handle = base:addevent(nil, 0, function ()
+			local ret = callback(socket_gettime());
+			if ret then
+				return 0, ret;
+			elseif event_handle then
+				return EVENT_LEAVE;
+			end
+		end
+		, delay);
+	end
+end
+
 return {
 
 	cfg = cfg,
@@ -864,6 +881,7 @@
 	closeall = closeallservers,
 	get_backend = get_backend,
 	hook_signal = hook_signal,
+	add_task = add_task,
 
 	__NAME = SCRIPT_NAME,
 	__DATE = LAST_MODIFIED,