// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Microsoft Software License Terms for the Azure Communications Services, Azure CPaaS, MICROSOFT AZURE COMMUNICATION CALLING EFFECTS
// See LICENSE file for license information.

function getDateInIsoFormat(){return(new Date).toISOString()}function stringifyObject(e){if(!e)return`${e}`;if(e instanceof Map)return mapToString(e);const t=e.toString();return t.endsWith("[object Object]")?JSON.stringify(e):t}function mapToString(e){const t={};return e.forEach(((e,n)=>{t[n.toString()]=e})),JSON.stringify(t)}function defer(){let e,t,n=!0;return{isPending:()=>n,promise:new Promise(((n,r)=>{e=n,t=r})),resolve:t=>{n&&(e(t),n=!1)},reject:e=>{n&&(t(e),n=!1)}}}function _setTimeout(e,t){return globalThis.setTimeout(e,t)}function _clearTimeout(e){globalThis.clearTimeout(e)}function wait(e,t){const n=defer();let r;try{r=e()}catch(e){return Promise.reject(n.reject(e))}if(t<0)return r.finally((()=>{n.resolve(r)})),n.promise;const i=_setTimeout((()=>{n.isPending()&&n.reject()}),t);return r.catch((e=>{_clearTimeout(i),n.isPending()&&n.reject(e)})).finally((()=>{_clearTimeout(i),n.isPending()&&n.resolve(r)})),n.promise}export{defer,getDateInIsoFormat,stringifyObject,wait};
