function y(f,s,r={}){const l=r.pauseWhenHidden??!0,c=r.runImmediately??!0;let e=null,t=!1,n=null,u=!1;async function i(){if(!u){u=!0;try{await f()}catch{}finally{u=!1}}}function d(){e===null&&(e=setInterval(i,s))}function a(){e!==null&&(clearInterval(e),e=null)}function o(){!l||typeof document>"u"||(n=()=>{t&&(document.hidden?a():(i(),d()))},document.addEventListener("visibilitychange",n))}function m(){n&&typeof document<"u"&&(document.removeEventListener("visibilitychange",n),n=null)}return{start(){t||(t=!0,o(),c&&i(),(!l||typeof document>"u"||!document.hidden)&&d())},stop(){t=!1,a(),m()},poke(){i()},get running(){return t}}}export{y as u};
