declare const webWorkerStr = "/* eslint-env worker */\n\nconst WorkerMessageType = {\n  START_KEEPALIVE: 'START_KEEPALIVE',\n  CLEAR_KEEPALIVE: 'CLEAR_KEEPALIVE',\n  SEND_KEEPALIVE: 'SEND_KEEPALIVE',\n  KEEPALIVE_RESULT: 'KEEPALIVE_RESULT',\n  KEEPALIVE_SUCCESS: 'KEEPALIVE_SUCCESS',\n  KEEPALIVE_FAILURE: 'KEEPALIVE_FAILURE',\n};\n\nlet keepaliveTimer;\nlet keepAliveRetryCount = 0;\nlet keepaliveInFlight = false;\n\nconst clearKeepaliveTimer = () => {\n  if (keepaliveTimer) {\n    clearInterval(keepaliveTimer);\n    keepaliveTimer = undefined;\n  }\n};\n\nconst messageHandler = (event) => {\n  const {type} = event.data;\n\n  if (type === WorkerMessageType.START_KEEPALIVE) {\n    const {interval, retryCountThreshold} = event.data;\n\n    clearKeepaliveTimer();\n    keepAliveRetryCount = 0;\n    keepaliveInFlight = false;\n\n    keepaliveTimer = setInterval(() => {\n      if (keepAliveRetryCount < retryCountThreshold && !keepaliveInFlight) {\n        keepaliveInFlight = true;\n        self.postMessage({\n          type: WorkerMessageType.SEND_KEEPALIVE,\n        });\n      }\n    }, interval * 1000);\n  }\n\n  if (type === WorkerMessageType.KEEPALIVE_RESULT) {\n    keepaliveInFlight = false;\n\n    if (event.data.err === undefined) {\n      if (keepAliveRetryCount > 0) {\n        self.postMessage({\n          type: WorkerMessageType.KEEPALIVE_SUCCESS,\n          statusCode: event.data.statusCode,\n        });\n      }\n\n      keepAliveRetryCount = 0;\n    } else {\n      keepAliveRetryCount += 1;\n      self.postMessage({\n        type: WorkerMessageType.KEEPALIVE_FAILURE,\n        err: event.data.err,\n        keepAliveRetryCount,\n      });\n    }\n  }\n\n  if (type === WorkerMessageType.CLEAR_KEEPALIVE) {\n    clearKeepaliveTimer();\n    keepAliveRetryCount = 0;\n    keepaliveInFlight = false;\n  }\n};\n\nself.addEventListener('message', messageHandler);\n";
export default webWorkerStr;
//# sourceMappingURL=webWorkerStr.d.ts.map