"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/asyncToGenerator"),t=require("@babel/runtime/regenerator"),r=require("../api/apiCore.js"),a=require("../../utils/delay.js");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=n(e),u=n(t),i=function(){var e=s.default(u.default.mark((function e(t,n){var s,i,c,o,f,l,p;return u.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=(s=n||{}).maxAttempts,c=void 0===i?60:i,o=s.retryDelay,f=void 0===o?1e3:o,l=0;case 2:if(!(l<c)){e.next=13;break}return e.next=5,r.get("/v2/tasks/".concat(t),{});case 5:if("running"===(p=e.sent).state){e.next=8;break}return e.abrupt("return",p);case 8:return e.next=10,a.delay(f);case 10:l+=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(t,r){return e.apply(this,arguments)}}(),c=function(){var e=s.default(u.default.mark((function e(t,a){var n,s,c;return u.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,r.post("/v2/tasks",{task:t});case 3:return s=e.sent,c=s.id,e.next=7,i(c,a);case 7:n=e.sent,e.next=13;break;case 10:e.prev=10,e.t0=e.catch(0),n={state:"failed",fail_reason:e.t0 instanceof Error?e.t0.message:String(e.t0)};case 13:if(null==a||!a.throwOnError||"succeeded"===n.state){e.next=15;break}throw n.fail_reason;case 15:return e.abrupt("return",n);case 16:case"end":return e.stop()}}),e,null,[[0,10]])})));return function(t,r){return e.apply(this,arguments)}}();exports.postTaskAndWaitResult=c;
//# sourceMappingURL=postTaskAndWaitResult.js.map
