import{logger as i}from"./util/logger.js";let e=null;function a(n){e=n,i.info("[runtime] setWeixinRuntime called, runtime set successfully")}function c(){if(!e)throw new Error("Weixin runtime not initialized");return e}const o=100,u=1e4;async function l(n=u){const t=Date.now();for(;!e;){if(Date.now()-t>n)throw new Error("Weixin runtime initialization timeout");await new Promise(r=>setTimeout(r,o))}return e}async function g(n){return n.channelRuntime?(i.debug("[runtime] channelRuntime from gateway context"),n.channelRuntime):e?(i.debug("[runtime] channelRuntime from register() global"),e.channel):(i.warn("[runtime] no channelRuntime on ctx and no global runtime yet; waiting for register()"),(await l(n.waitTimeoutMs??u)).channel)}export{c as getWeixinRuntime,g as resolveWeixinChannelRuntime,a as setWeixinRuntime,l as waitForWeixinRuntime};
