首页 > 代码库 > [lua]异步串行流程*协程
[lua]异步串行流程*协程
local function param_pack( params, callback ) local host = params[1] local service = table.remove(params, 2) table.insert(params, callback) return host, service, params end local function asyncall( ... ) local co, main = coroutine.running() if main then print(‘Please use .call(...) in .run(func) context‘) return end local function callback( ... ) local params = {co, ... } return coroutine.resume(unpack(params)) end local host, service local params = {...} if type(params[#params]) == ‘function‘ then host, service, params = table.remove(params)(params, callback) else host, service, params = param_pack(params, callback) end if type(host[service]) == ‘function‘ then return coroutine.yield(host[service](unpack(params))) else print(‘service:‘..service..‘ not implement at ‘..tostring(host)) end end local function runProcess( func, ... ) local co = coroutine.create(func) local params = {co, ...} return coroutine.resume(unpack(params)) end local target = { call = asyncall, run = runProcess } return target --[[ -- example local Plugin = plugin.AgentManager:getUserPlugin() target.run(function ( ... ) local code, msg, info = target.call(Plugin, ‘queryThirdInfo‘, ‘weixin‘) if code == AsyncQueryStatus.kSuccess then dump(info) else print(msg) end code, msg = target.call(Plugin, ‘queryThirdAccountBindState‘, ‘weixin‘) end) --]]
[lua]异步串行流程*协程
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。