@aws-sdk/util-waiter
Advanced tools
Comparing version 3.180.0 to 3.183.0
@@ -6,2 +6,10 @@ # Change Log | ||
# [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03) | ||
**Note:** Version bump only for package @aws-sdk/util-waiter | ||
# [3.180.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.179.0...v3.180.0) (2022-09-27) | ||
@@ -8,0 +16,0 @@ |
@@ -1,26 +0,23 @@ | ||
import { __assign, __awaiter, __generator } from "tslib"; | ||
import { runPolling } from "./poller"; | ||
import { validateWaiterOptions } from "./utils"; | ||
import { waiterServiceDefaults, WaiterState } from "./waiter"; | ||
var abortTimeout = function (abortSignal) { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2, new Promise(function (resolve) { | ||
abortSignal.onabort = function () { return resolve({ state: WaiterState.ABORTED }); }; | ||
})]; | ||
const abortTimeout = async (abortSignal) => { | ||
return new Promise((resolve) => { | ||
abortSignal.onabort = () => resolve({ state: WaiterState.ABORTED }); | ||
}); | ||
}); }; | ||
export var createWaiter = function (options, input, acceptorChecks) { return __awaiter(void 0, void 0, void 0, function () { | ||
var params, exitConditions; | ||
return __generator(this, function (_a) { | ||
params = __assign(__assign({}, waiterServiceDefaults), options); | ||
validateWaiterOptions(params); | ||
exitConditions = [runPolling(params, input, acceptorChecks)]; | ||
if (options.abortController) { | ||
exitConditions.push(abortTimeout(options.abortController.signal)); | ||
} | ||
if (options.abortSignal) { | ||
exitConditions.push(abortTimeout(options.abortSignal)); | ||
} | ||
return [2, Promise.race(exitConditions)]; | ||
}); | ||
}); }; | ||
}; | ||
export const createWaiter = async (options, input, acceptorChecks) => { | ||
const params = { | ||
...waiterServiceDefaults, | ||
...options, | ||
}; | ||
validateWaiterOptions(params); | ||
const exitConditions = [runPolling(params, input, acceptorChecks)]; | ||
if (options.abortController) { | ||
exitConditions.push(abortTimeout(options.abortController.signal)); | ||
} | ||
if (options.abortSignal) { | ||
exitConditions.push(abortTimeout(options.abortSignal)); | ||
} | ||
return Promise.race(exitConditions); | ||
}; |
@@ -1,52 +0,33 @@ | ||
import { __awaiter, __generator } from "tslib"; | ||
import { sleep } from "./utils/sleep"; | ||
import { WaiterState } from "./waiter"; | ||
var exponentialBackoffWithJitter = function (minDelay, maxDelay, attemptCeiling, attempt) { | ||
const exponentialBackoffWithJitter = (minDelay, maxDelay, attemptCeiling, attempt) => { | ||
if (attempt > attemptCeiling) | ||
return maxDelay; | ||
var delay = minDelay * Math.pow(2, (attempt - 1)); | ||
const delay = minDelay * 2 ** (attempt - 1); | ||
return randomInRange(minDelay, delay); | ||
}; | ||
var randomInRange = function (min, max) { return min + Math.random() * (max - min); }; | ||
export var runPolling = function (_a, input, acceptorChecks) { | ||
var minDelay = _a.minDelay, maxDelay = _a.maxDelay, maxWaitTime = _a.maxWaitTime, abortController = _a.abortController, client = _a.client, abortSignal = _a.abortSignal; | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
var _b, state, reason, currentAttempt, waitUntil, attemptCeiling, delay, _c, state_1, reason_1; | ||
var _d; | ||
return __generator(this, function (_e) { | ||
switch (_e.label) { | ||
case 0: return [4, acceptorChecks(client, input)]; | ||
case 1: | ||
_b = _e.sent(), state = _b.state, reason = _b.reason; | ||
if (state !== WaiterState.RETRY) { | ||
return [2, { state: state, reason: reason }]; | ||
} | ||
currentAttempt = 1; | ||
waitUntil = Date.now() + maxWaitTime * 1000; | ||
attemptCeiling = Math.log(maxDelay / minDelay) / Math.log(2) + 1; | ||
_e.label = 2; | ||
case 2: | ||
if (!true) return [3, 5]; | ||
if (((_d = abortController === null || abortController === void 0 ? void 0 : abortController.signal) === null || _d === void 0 ? void 0 : _d.aborted) || (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) { | ||
return [2, { state: WaiterState.ABORTED }]; | ||
} | ||
delay = exponentialBackoffWithJitter(minDelay, maxDelay, attemptCeiling, currentAttempt); | ||
if (Date.now() + delay * 1000 > waitUntil) { | ||
return [2, { state: WaiterState.TIMEOUT }]; | ||
} | ||
return [4, sleep(delay)]; | ||
case 3: | ||
_e.sent(); | ||
return [4, acceptorChecks(client, input)]; | ||
case 4: | ||
_c = _e.sent(), state_1 = _c.state, reason_1 = _c.reason; | ||
if (state_1 !== WaiterState.RETRY) { | ||
return [2, { state: state_1, reason: reason_1 }]; | ||
} | ||
currentAttempt += 1; | ||
return [3, 2]; | ||
case 5: return [2]; | ||
} | ||
}); | ||
}); | ||
const randomInRange = (min, max) => min + Math.random() * (max - min); | ||
export const runPolling = async ({ minDelay, maxDelay, maxWaitTime, abortController, client, abortSignal }, input, acceptorChecks) => { | ||
const { state, reason } = await acceptorChecks(client, input); | ||
if (state !== WaiterState.RETRY) { | ||
return { state, reason }; | ||
} | ||
let currentAttempt = 1; | ||
const waitUntil = Date.now() + maxWaitTime * 1000; | ||
const attemptCeiling = Math.log(maxDelay / minDelay) / Math.log(2) + 1; | ||
while (true) { | ||
if (abortController?.signal?.aborted || abortSignal?.aborted) { | ||
return { state: WaiterState.ABORTED }; | ||
} | ||
const delay = exponentialBackoffWithJitter(minDelay, maxDelay, attemptCeiling, currentAttempt); | ||
if (Date.now() + delay * 1000 > waitUntil) { | ||
return { state: WaiterState.TIMEOUT }; | ||
} | ||
await sleep(delay); | ||
const { state, reason } = await acceptorChecks(client, input); | ||
if (state !== WaiterState.RETRY) { | ||
return { state, reason }; | ||
} | ||
currentAttempt += 1; | ||
} | ||
}; |
@@ -1,3 +0,3 @@ | ||
export var sleep = function (seconds) { | ||
return new Promise(function (resolve) { return setTimeout(resolve, seconds * 1000); }); | ||
export const sleep = (seconds) => { | ||
return new Promise((resolve) => setTimeout(resolve, seconds * 1000)); | ||
}; |
@@ -1,17 +0,17 @@ | ||
export var validateWaiterOptions = function (options) { | ||
export const validateWaiterOptions = (options) => { | ||
if (options.maxWaitTime < 1) { | ||
throw new Error("WaiterConfiguration.maxWaitTime must be greater than 0"); | ||
throw new Error(`WaiterConfiguration.maxWaitTime must be greater than 0`); | ||
} | ||
else if (options.minDelay < 1) { | ||
throw new Error("WaiterConfiguration.minDelay must be greater than 0"); | ||
throw new Error(`WaiterConfiguration.minDelay must be greater than 0`); | ||
} | ||
else if (options.maxDelay < 1) { | ||
throw new Error("WaiterConfiguration.maxDelay must be greater than 0"); | ||
throw new Error(`WaiterConfiguration.maxDelay must be greater than 0`); | ||
} | ||
else if (options.maxWaitTime <= options.minDelay) { | ||
throw new Error("WaiterConfiguration.maxWaitTime [".concat(options.maxWaitTime, "] must be greater than WaiterConfiguration.minDelay [").concat(options.minDelay, "] for this waiter")); | ||
throw new Error(`WaiterConfiguration.maxWaitTime [${options.maxWaitTime}] must be greater than WaiterConfiguration.minDelay [${options.minDelay}] for this waiter`); | ||
} | ||
else if (options.maxDelay < options.minDelay) { | ||
throw new Error("WaiterConfiguration.maxDelay [".concat(options.maxDelay, "] must be greater than WaiterConfiguration.minDelay [").concat(options.minDelay, "] for this waiter")); | ||
throw new Error(`WaiterConfiguration.maxDelay [${options.maxDelay}] must be greater than WaiterConfiguration.minDelay [${options.minDelay}] for this waiter`); | ||
} | ||
}; |
@@ -1,3 +0,2 @@ | ||
import { __assign } from "tslib"; | ||
export var waiterServiceDefaults = { | ||
export const waiterServiceDefaults = { | ||
minDelay: 2, | ||
@@ -14,5 +13,8 @@ maxDelay: 120, | ||
})(WaiterState || (WaiterState = {})); | ||
export var checkExceptions = function (result) { | ||
export const checkExceptions = (result) => { | ||
if (result.state === WaiterState.ABORTED) { | ||
var abortError = new Error("".concat(JSON.stringify(__assign(__assign({}, result), { reason: "Request was aborted" })))); | ||
const abortError = new Error(`${JSON.stringify({ | ||
...result, | ||
reason: "Request was aborted", | ||
})}`); | ||
abortError.name = "AbortError"; | ||
@@ -22,3 +24,6 @@ throw abortError; | ||
else if (result.state === WaiterState.TIMEOUT) { | ||
var timeoutError = new Error("".concat(JSON.stringify(__assign(__assign({}, result), { reason: "Waiter has timed out" })))); | ||
const timeoutError = new Error(`${JSON.stringify({ | ||
...result, | ||
reason: "Waiter has timed out", | ||
})}`); | ||
timeoutError.name = "TimeoutError"; | ||
@@ -28,5 +33,5 @@ throw timeoutError; | ||
else if (result.state !== WaiterState.SUCCESS) { | ||
throw new Error("".concat(JSON.stringify({ result: result }))); | ||
throw new Error(`${JSON.stringify({ result })}`); | ||
} | ||
return result; | ||
}; |
{ | ||
"name": "@aws-sdk/util-waiter", | ||
"version": "3.180.0", | ||
"version": "3.183.0", | ||
"description": "Shared utilities for client waiters for the AWS SDK", | ||
"dependencies": { | ||
"@aws-sdk/abort-controller": "3.178.0", | ||
"@aws-sdk/types": "3.178.0", | ||
"@aws-sdk/abort-controller": "3.183.0", | ||
"@aws-sdk/types": "3.183.0", | ||
"tslib": "^2.3.1" | ||
@@ -9,0 +9,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39203
368
+ Added@aws-sdk/abort-controller@3.183.0(transitive)
+ Added@aws-sdk/types@3.183.0(transitive)
- Removed@aws-sdk/abort-controller@3.178.0(transitive)
- Removed@aws-sdk/types@3.178.0(transitive)
Updated@aws-sdk/types@3.183.0