{"version":3,"sources":["../../src/utils/await_interval.ts"],"sourcesContent":["/* this function is used to await a condition to be met with a certain interval and timeout\n * until the condition is met or the timeout is reached */\ntype awaitIntervalOptions = {\n    condition: () => any;\n    timeout?: number;\n    interval?: number;\n    error?: string;\n}\n\nasync function interval_await({ condition, timeout = 10000, interval = 100, error = 'hasTimedOut' }: awaitIntervalOptions): Promise<any> {\n    return await new Promise( async (resolve, reject) => {\n        let timeout_obj : NodeJS.Timeout\n        let interval_obj : NodeJS.Timeout\n        // set a timeout to reject the promise\n        if(timeout > 0){\n            timeout_obj = setTimeout(() => {\n                clearInterval(interval_obj);\n                reject(new Error(error));\n            }, timeout);\n        }\n        // set an interval to check the condition\n        interval_obj = setInterval( async  () => {\n            // check if the condition is met\n            let result: Boolean = await condition();\n            if(result === true) {\n                clearInterval(interval_obj);\n                clearTimeout(timeout_obj);\n                resolve(result);\n            }\n        }, interval);\n    }).catch( error => {\n        throw error;\n    });\n}\n\nexport default interval_await;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,eAAe,eAAe,EAAE,WAAW,UAAU,KAAO,WAAW,KAAK,QAAQ,cAAc,GAAuC;AACrI,SAAO,MAAM,IAAI,QAAS,OAAO,SAAS,WAAW;AACjD,QAAI;AACJ,QAAI;AAEJ,QAAG,UAAU,GAAE;AACX,oBAAc,WAAW,MAAM;AAC3B,sBAAc,YAAY;AAC1B,eAAO,IAAI,MAAM,KAAK,CAAC;AAAA,MAC3B,GAAG,OAAO;AAAA,IACd;AAEA,mBAAe,YAAa,YAAa;AAErC,UAAI,SAAkB,MAAM,UAAU;AACtC,UAAG,WAAW,MAAM;AAChB,sBAAc,YAAY;AAC1B,qBAAa,WAAW;AACxB,gBAAQ,MAAM;AAAA,MAClB;AAAA,IACJ,GAAG,QAAQ;AAAA,EACf,CAAC,EAAE,MAAO,CAAAA,WAAS;AACf,UAAMA;AAAA,EACV,CAAC;AACL;AAEA,IAAO,yBAAQ;","names":["error"]}