"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require('./../../ext-esm/tslib/tslib.es6.js'),t=require("../api/apiCore.js"),r=require("../../utils/delay.js"),s=function(s,a){return e.__awaiter(void 0,void 0,void 0,(function(){var n,i,o,u,c,l,d;return e.__generator(this,(function(e){switch(e.label){case 0:i=(n=a||{}).maxAttempts,o=void 0===i?60:i,u=n.retryDelay,c=void 0===u?1e3:u,l=0,e.label=1;case 1:return l<o?[4,t.get("/v2/tasks/".concat(s),{})]:[3,5];case 2:return"running"!==(d=e.sent()).state?[2,d]:[4,r.delay(c)];case 3:e.sent(),e.label=4;case 4:return l+=1,[3,1];case 5:return[2,{state:"failed",fail_reason:"Task timed out"}]}}))}))};exports.postTaskAndWaitResult=function(r,a){return e.__awaiter(void 0,void 0,void 0,(function(){var n,i,o;return e.__generator(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),[4,t.post("/v2/tasks",{task:r})];case 1:return i=e.sent().id,[4,s(i,a)];case 2:return n=e.sent(),[3,4];case 3:return o=e.sent(),n={state:"failed",fail_reason:o},[3,4];case 4:if((null==a?void 0:a.throwOnError)&&"succeeded"!==n.state)throw n.fail_reason;return[2,n]}}))}))};
