[lua]异步串行流程*协程
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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]异步串行流程*协程的主要内容,如果未能解决你的问题,请参考以下文章