Comparison

net/server_event.lua @ 6862:7a81fb23de5d

server_event: Remove needless scoping around add_task
author Kim Alvefur <zash@zash.se>
date Fri, 25 Sep 2015 18:07:08 +0200
parent 6861:39789f1669cb
child 6929:03bc9e197fcc
comparison
equal deleted inserted replaced
6861:39789f1669cb 6862:7a81fb23de5d
794 end 794 end
795 end 795 end
796 sender:set_mode("*a"); 796 sender:set_mode("*a");
797 end 797 end
798 798
799 local add_task do 799 local function add_task(delay, callback)
800 local EVENT_LEAVE = (event.core and event.core.LEAVE) or -1; 800 local event_handle;
801 local socket_gettime = socket.gettime 801 event_handle = base:addevent(nil, 0, function ()
802 function add_task(delay, callback) 802 local ret = callback(socket_gettime());
803 local event_handle; 803 if ret then
804 event_handle = base:addevent(nil, 0, function () 804 return 0, ret;
805 local ret = callback(socket_gettime()); 805 elseif event_handle then
806 if ret then 806 return -1;
807 return 0, ret; 807 end
808 elseif event_handle then 808 end
809 return EVENT_LEAVE; 809 , delay);
810 end
811 end
812 , delay);
813 end
814 end 810 end
815 811
816 return { 812 return {
817 cfg = cfg, 813 cfg = cfg,
818 base = base, 814 base = base,