|
| 1 | +import { checkExceptions, createWaiter, WaiterConfiguration, WaiterResult, WaiterState } from "@aws-sdk/util-waiter"; |
| 2 | + |
| 3 | +import { DescribeNatGatewaysCommand, DescribeNatGatewaysCommandInput } from "../commands/DescribeNatGatewaysCommand"; |
| 4 | +import { EC2Client } from "../EC2Client"; |
| 5 | + |
| 6 | +const checkState = async (client: EC2Client, input: DescribeNatGatewaysCommandInput): Promise<WaiterResult> => { |
| 7 | + let reason; |
| 8 | + try { |
| 9 | + const result: any = await client.send(new DescribeNatGatewaysCommand(input)); |
| 10 | + reason = result; |
| 11 | + try { |
| 12 | + const returnComparator = () => { |
| 13 | + const flat_1: any[] = [].concat(...result.NatGateways); |
| 14 | + const projection_3 = flat_1.map((element_2: any) => { |
| 15 | + return element_2.State; |
| 16 | + }); |
| 17 | + return projection_3; |
| 18 | + }; |
| 19 | + let allStringEq_5 = returnComparator().length > 0; |
| 20 | + for (const element_4 of returnComparator()) { |
| 21 | + allStringEq_5 = allStringEq_5 && element_4 == "deleted"; |
| 22 | + } |
| 23 | + if (allStringEq_5) { |
| 24 | + return { state: WaiterState.SUCCESS, reason }; |
| 25 | + } |
| 26 | + } catch (e) {} |
| 27 | + } catch (exception) { |
| 28 | + reason = exception; |
| 29 | + if (exception.name && exception.name == "NatGatewayNotFound") { |
| 30 | + return { state: WaiterState.SUCCESS, reason }; |
| 31 | + } |
| 32 | + } |
| 33 | + return { state: WaiterState.RETRY, reason }; |
| 34 | +}; |
| 35 | +/** |
| 36 | + * |
| 37 | + * @deprecated Use waitUntilNatGatewayDeleted instead. waitForNatGatewayDeleted does not throw error in non-success cases. |
| 38 | + */ |
| 39 | +export const waitForNatGatewayDeleted = async ( |
| 40 | + params: WaiterConfiguration<EC2Client>, |
| 41 | + input: DescribeNatGatewaysCommandInput |
| 42 | +): Promise<WaiterResult> => { |
| 43 | + const serviceDefaults = { minDelay: 15, maxDelay: 120 }; |
| 44 | + return createWaiter({ ...serviceDefaults, ...params }, input, checkState); |
| 45 | +}; |
| 46 | +/** |
| 47 | + * |
| 48 | + * @param params - Waiter configuration options. |
| 49 | + * @param input - The input to DescribeNatGatewaysCommand for polling. |
| 50 | + */ |
| 51 | +export const waitUntilNatGatewayDeleted = async ( |
| 52 | + params: WaiterConfiguration<EC2Client>, |
| 53 | + input: DescribeNatGatewaysCommandInput |
| 54 | +): Promise<WaiterResult> => { |
| 55 | + const serviceDefaults = { minDelay: 15, maxDelay: 120 }; |
| 56 | + const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState); |
| 57 | + return checkExceptions(result); |
| 58 | +}; |
0 commit comments