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