import e from"@babel/runtime/helpers/asyncToGenerator";import r from"@babel/runtime/regenerator";import{post as t,get as n}from"../api/apiCore.js";import{delay as a}from"../../utils/delay.js";var s=function(){var t=e(r.mark((function e(t,s){var o,u,i,c,p,f,l;return r.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:u=(o=s||{}).maxAttempts,i=void 0===u?60:u,c=o.retryDelay,p=void 0===c?1e3:c,f=0;case 2:if(!(f<i)){e.next=13;break}return e.next=5,n("/v2/tasks/".concat(t),{});case 5:if("running"===(l=e.sent).state){e.next=8;break}return e.abrupt("return",l);case 8:return e.next=10,a(p);case 10:f+=1,e.next=2;break;case 13:return e.abrupt("return",{state:"failed",fail_reason:"Task timed out"});case 14:case"end":return e.stop()}}),e)})));return function(e,r){return t.apply(this,arguments)}}(),o=function(){var n=e(r.mark((function e(n,a){var o,u,i;return r.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t("/v2/tasks",{task:n});case 3:return u=e.sent,i=u.id,e.next=7,s(i,a);case 7:o=e.sent,e.next=13;break;case 10:e.prev=10,e.t0=e.catch(0),o={state:"failed",fail_reason:e.t0 instanceof Error?e.t0.message:String(e.t0)};case 13:if(null==a||!a.throwOnError||"succeeded"===o.state){e.next=15;break}throw o.fail_reason;case 15:return e.abrupt("return",o);case 16:case"end":return e.stop()}}),e,null,[[0,10]])})));return function(e,r){return n.apply(this,arguments)}}();export{o as postTaskAndWaitResult};
//# sourceMappingURL=postTaskAndWaitResult.js.map
