From fb8025e3db7c0071c726803062530f53490714a0 Mon Sep 17 00:00:00 2001 From: huahua132 <958677003@qq.com> Date: Fri, 6 Dec 2024 10:58:31 +0800 Subject: [PATCH] =?UTF-8?q?fix=20reload=E4=B9=8B=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E6=97=A7=E6=9C=8D=E5=8A=A1=E4=B8=80=E7=9B=B4=E8=A7=A6=E5=8F=91?= =?UTF-8?q?watch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lualib/skynet-fly/client/contriner_client.lua | 7 +++++++ lualib/skynet-fly/time_extend/wait.lua | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lualib/skynet-fly/client/contriner_client.lua b/lualib/skynet-fly/client/contriner_client.lua index 8f773605f..262499c8c 100644 --- a/lualib/skynet-fly/client/contriner_client.lua +++ b/lualib/skynet-fly/client/contriner_client.lua @@ -2,6 +2,7 @@ local skynet = require "skynet" local module_info = require "skynet-fly.etc.module_info" local skynet_util = require "skynet-fly.utils.skynet_util" local table_util = require "skynet-fly.utils.table_util" +local wait = require "skynet-fly.time_extend.wait" local setmetatable = setmetatable local assert = assert local pairs = pairs @@ -34,6 +35,7 @@ local g_querycbed_map = {} --查询到地址已执行回调列表 local g_updated_map = {} --更新地址的回调列表 local g_always_swtich_map = {}--总能切换的modulename服务,不受is_close_swtich限制 local g_pre_gc_time = 0 --上次调用gc的时间 +local g_wait = wait:new() local SERVICE_NAME = SERVICE_NAME --弱引用原表 @@ -106,6 +108,7 @@ local function monitor(t,key) while not IS_CLOSE do local old_version = g_mod_svr_version_map[key] local id_list,name_id_list,version = skynet.call(get_contriner_mgr_addr(), 'lua', 'watch', SELF_ADDRESS, key, old_version) + skynet.error("monitor ", key) if not is_close_swtich or g_always_swtich_map[key] then add_id_list_week(key,id_list) register_visitor(id_list) @@ -117,6 +120,9 @@ local function monitor(t,key) if updated then skynet.fork(call_back_updated, updated) end + else + --等待开放swtich + g_wait:wait("open_swtich") end end end @@ -225,6 +231,7 @@ end --开启服务切换 function M:open_switch() is_close_swtich = false + g_wait:wakeup("open_switch") end skynet.init(function() diff --git a/lualib/skynet-fly/time_extend/wait.lua b/lualib/skynet-fly/time_extend/wait.lua index 0de534143..47c0c3434 100644 --- a/lualib/skynet-fly/time_extend/wait.lua +++ b/lualib/skynet-fly/time_extend/wait.lua @@ -13,7 +13,6 @@ local M = {} local mata = {__index = M} function M:new(time_out) - assert(time_out > 0, "time_out err") local t = { map = {}, list = {}, @@ -34,11 +33,16 @@ function M:wait(k) end local co = coroutine.running() - local ti = timer:new(self.time_out, 1, skynet.wakeup, co) + local ti = nil + if self.time_out then + ti = timer:new(self.time_out, 1, skynet.wakeup, co) + end map[k][co] = true tinsert(list[k], co) skynet.wait(co) - ti:cancel() + if ti then + ti:cancel() + end map[k][co] = nil local ls = list[k] for i = 1,#ls do