Skip to content

Commit

Permalink
feat: add finalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
godu committed Jan 18, 2025
1 parent 5746981 commit b7a58d4
Show file tree
Hide file tree
Showing 38 changed files with 295 additions and 110 deletions.
41 changes: 41 additions & 0 deletions .changeset/five-poems-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
"@effect-aws/client-api-gateway-management-api": minor
"@effect-aws/client-cognito-identity-provider": minor
"@effect-aws/client-opensearch-serverless": minor
"@effect-aws/client-cloudwatch-events": minor
"@effect-aws/client-cloudwatch-logs": minor
"@effect-aws/client-secrets-manager": minor
"@effect-aws/client-organizations": minor
"@effect-aws/client-auto-scaling": minor
"@effect-aws/client-cloudsearch": minor
"@effect-aws/client-elasticache": minor
"@effect-aws/client-eventbridge": minor
"@effect-aws/client-cloudtrail": minor
"@effect-aws/client-cloudwatch": minor
"@effect-aws/client-codedeploy": minor
"@effect-aws/client-opensearch": minor
"@effect-aws/client-scheduler": minor
"@effect-aws/client-dynamodb": minor
"@effect-aws/client-textract": minor
"@effect-aws/client-account": minor
"@effect-aws/client-bedrock": minor
"@effect-aws/client-kinesis": minor
"@effect-aws/client-lambda": minor
"@effect-aws/lib-dynamodb": minor
"@effect-aws/client-ec2": minor
"@effect-aws/client-ecr": minor
"@effect-aws/client-ecs": minor
"@effect-aws/client-iam": minor
"@effect-aws/client-kms": minor
"@effect-aws/client-rds": minor
"@effect-aws/client-sfn": minor
"@effect-aws/client-sns": minor
"@effect-aws/client-sqs": minor
"@effect-aws/client-ssm": minor
"@effect-aws/client-sts": minor
"@effect-aws/client-mq": minor
"@effect-aws/client-s3": minor
"@effect-aws/lib-dynamodb": minor
---

Destroy client after layer lifecycle to release idle connections.
10 changes: 7 additions & 3 deletions packages/client-account/src/AccountClientInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ export class AccountClientInstance extends Context.Tag(
* @since 1.0.0
* @category constructors
*/
export const makeAccountClientInstance = Effect.map(
export const makeAccountClientInstance = Effect.flatMap(
AccountClientInstanceConfig,
(config) => new AccountClient(config),
(config) =>
Effect.acquireRelease(
Effect.sync(() => new AccountClient(config)),
(client) => Effect.sync(() => client.destroy()),
),
);

/**
* @since 1.0.0
* @category layers
*/
export const AccountClientInstanceLayer = Layer.effect(
export const AccountClientInstanceLayer = Layer.scoped(
AccountClientInstance,
makeAccountClientInstance,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ export class ApiGatewayManagementApiClientInstance extends Context.Tag(
* @since 1.0.0
* @category constructors
*/
export const makeApiGatewayManagementApiClientInstance = Effect.map(
export const makeApiGatewayManagementApiClientInstance = Effect.flatMap(
ApiGatewayManagementApiClientInstanceConfig,
(config) => new ApiGatewayManagementApiClient(config),
(config) =>
Effect.acquireRelease(
Effect.sync(() => new ApiGatewayManagementApiClient(config)),
(client) => Effect.sync(() => client.destroy()),
),
);

/**
* @since 1.0.0
* @category layers
*/
export const ApiGatewayManagementApiClientInstanceLayer = Layer.effect(
export const ApiGatewayManagementApiClientInstanceLayer = Layer.scoped(
ApiGatewayManagementApiClientInstance,
makeApiGatewayManagementApiClientInstance,
);
Expand Down
10 changes: 7 additions & 3 deletions packages/client-auto-scaling/src/AutoScalingClientInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ export class AutoScalingClientInstance extends Context.Tag(
* @since 1.0.0
* @category constructors
*/
export const makeAutoScalingClientInstance = Effect.map(
export const makeAutoScalingClientInstance = Effect.flatMap(
AutoScalingClientInstanceConfig,
(config) => new AutoScalingClient(config),
(config) =>
Effect.acquireRelease(
Effect.sync(() => new AutoScalingClient(config)),
(client) => Effect.sync(() => client.destroy()),
),
);

/**
* @since 1.0.0
* @category layers
*/
export const AutoScalingClientInstanceLayer = Layer.effect(
export const AutoScalingClientInstanceLayer = Layer.scoped(
AutoScalingClientInstance,
makeAutoScalingClientInstance,
);
Expand Down
10 changes: 7 additions & 3 deletions packages/client-bedrock/src/BedrockClientInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ export class BedrockClientInstance extends Context.Tag(
* @since 1.0.0
* @category constructors
*/
export const makeBedrockClientInstance = Effect.map(
export const makeBedrockClientInstance = Effect.flatMap(
BedrockClientInstanceConfig,
(config) => new BedrockClient(config),
(config) =>
Effect.acquireRelease(
Effect.sync(() => new BedrockClient(config)),
(client) => Effect.sync(() => client.destroy()),
),
);

/**
* @since 1.0.0
* @category layers
*/
export const BedrockClientInstanceLayer = Layer.effect(
export const BedrockClientInstanceLayer = Layer.scoped(
BedrockClientInstance,
makeBedrockClientInstance,
);
Expand Down
10 changes: 7 additions & 3 deletions packages/client-cloudsearch/src/CloudSearchClientInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ export class CloudSearchClientInstance extends Context.Tag(
* @since 1.0.0
* @category constructors
*/
export const makeCloudSearchClientInstance = Effect.map(
export const makeCloudSearchClientInstance = Effect.flatMap(
CloudSearchClientInstanceConfig,
(config) => new CloudSearchClient(config),
(config) =>
Effect.acquireRelease(
Effect.sync(() => new CloudSearchClient(config)),
(client) => Effect.sync(() => client.destroy()),
),
);

/**
* @since 1.0.0
* @category layers
*/
export const CloudSearchClientInstanceLayer = Layer.effect(
export const CloudSearchClientInstanceLayer = Layer.scoped(
CloudSearchClientInstance,
makeCloudSearchClientInstance,
);
Expand Down
10 changes: 7 additions & 3 deletions packages/client-cloudtrail/src/CloudTrailClientInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ export class CloudTrailClientInstance extends Context.Tag(
* @since 1.0.0
* @category constructors
*/
export const makeCloudTrailClientInstance = Effect.map(
export const makeCloudTrailClientInstance = Effect.flatMap(
CloudTrailClientInstanceConfig,
(config) => new CloudTrailClient(config),
(config) =>
Effect.acquireRelease(
Effect.sync(() => new CloudTrailClient(config)),
(client) => Effect.sync(() => client.destroy()),
),
);

/**
* @since 1.0.0
* @category layers
*/
export const CloudTrailClientInstanceLayer = Layer.effect(
export const CloudTrailClientInstanceLayer = Layer.scoped(
CloudTrailClientInstance,
makeCloudTrailClientInstance,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ export class CloudWatchEventsClientInstance extends Context.Tag(
* @since 1.0.0
* @category constructors
*/
export const makeCloudWatchEventsClientInstance = Effect.map(
export const makeCloudWatchEventsClientInstance = Effect.flatMap(
CloudWatchEventsClientInstanceConfig,
(config) => new CloudWatchEventsClient(config),
(config) =>
Effect.acquireRelease(
Effect.sync(() => new CloudWatchEventsClient(config)),
(client) => Effect.sync(() => client.destroy()),
),
);

/**
* @since 1.0.0
* @category layers
*/
export const CloudWatchEventsClientInstanceLayer = Layer.effect(
export const CloudWatchEventsClientInstanceLayer = Layer.scoped(
CloudWatchEventsClientInstance,
makeCloudWatchEventsClientInstance,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ export class CloudWatchLogsClientInstance extends Context.Tag(
* @since 1.0.0
* @category constructors
*/
export const makeCloudWatchLogsClientInstance = Effect.map(
export const makeCloudWatchLogsClientInstance = Effect.flatMap(
CloudWatchLogsClientInstanceConfig,
(config) => new CloudWatchLogsClient(config),
(config) =>
Effect.acquireRelease(
Effect.sync(() => new CloudWatchLogsClient(config)),
(client) => Effect.sync(() => client.destroy()),
),
);

/**
* @since 1.0.0
* @category layers
*/
export const CloudWatchLogsClientInstanceLayer = Layer.effect(
export const CloudWatchLogsClientInstanceLayer = Layer.scoped(
CloudWatchLogsClientInstance,
makeCloudWatchLogsClientInstance,
);
Expand Down
10 changes: 7 additions & 3 deletions packages/client-cloudwatch/src/CloudWatchClientInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ export class CloudWatchClientInstance extends Context.Tag(
* @since 1.0.0
* @category constructors
*/
export const makeCloudWatchClientInstance = Effect.map(
export const makeCloudWatchClientInstance = Effect.flatMap(
CloudWatchClientInstanceConfig,
(config) => new CloudWatchClient(config),
(config) =>
Effect.acquireRelease(
Effect.sync(() => new CloudWatchClient(config)),
(client) => Effect.sync(() => client.destroy()),
),
);

/**
* @since 1.0.0
* @category layers
*/
export const CloudWatchClientInstanceLayer = Layer.effect(
export const CloudWatchClientInstanceLayer = Layer.scoped(
CloudWatchClientInstance,
makeCloudWatchClientInstance,
);
Expand Down
10 changes: 7 additions & 3 deletions packages/client-codedeploy/src/CodeDeployClientInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ export class CodeDeployClientInstance extends Context.Tag(
* @since 1.0.0
* @category constructors
*/
export const makeCodeDeployClientInstance = Effect.map(
export const makeCodeDeployClientInstance = Effect.flatMap(
CodeDeployClientInstanceConfig,
(config) => new CodeDeployClient(config),
(config) =>
Effect.acquireRelease(
Effect.sync(() => new CodeDeployClient(config)),
(client) => Effect.sync(() => client.destroy()),
),
);

/**
* @since 1.0.0
* @category layers
*/
export const CodeDeployClientInstanceLayer = Layer.effect(
export const CodeDeployClientInstanceLayer = Layer.scoped(
CodeDeployClientInstance,
makeCodeDeployClientInstance,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ export class CognitoIdentityProviderClientInstance extends Context.Tag(
* @since 1.0.0
* @category constructors
*/
export const makeCognitoIdentityProviderClientInstance = Effect.map(
export const makeCognitoIdentityProviderClientInstance = Effect.flatMap(
CognitoIdentityProviderClientInstanceConfig,
(config) => new CognitoIdentityProviderClient(config),
(config) =>
Effect.acquireRelease(
Effect.sync(() => new CognitoIdentityProviderClient(config)),
(client) => Effect.sync(() => client.destroy()),
),
);

/**
* @since 1.0.0
* @category layers
*/
export const CognitoIdentityProviderClientInstanceLayer = Layer.effect(
export const CognitoIdentityProviderClientInstanceLayer = Layer.scoped(
CognitoIdentityProviderClientInstance,
makeCognitoIdentityProviderClientInstance,
);
Expand Down
10 changes: 7 additions & 3 deletions packages/client-dynamodb/src/DynamoDBClientInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ export class DynamoDBClientInstance extends Context.Tag(
* @since 1.0.0
* @category constructors
*/
export const makeDynamoDBClientInstance = Effect.map(
export const makeDynamoDBClientInstance = Effect.flatMap(
DynamoDBClientInstanceConfig,
(config) => new DynamoDBClient(config),
(config) =>
Effect.acquireRelease(
Effect.sync(() => new DynamoDBClient(config)),
(client) => Effect.sync(() => client.destroy()),
),
);

/**
* @since 1.0.0
* @category layers
*/
export const DynamoDBClientInstanceLayer = Layer.effect(
export const DynamoDBClientInstanceLayer = Layer.scoped(
DynamoDBClientInstance,
makeDynamoDBClientInstance,
);
Expand Down
10 changes: 7 additions & 3 deletions packages/client-ec2/src/EC2ClientInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ export class EC2ClientInstance extends Context.Tag(
* @since 1.0.0
* @category constructors
*/
export const makeEC2ClientInstance = Effect.map(
export const makeEC2ClientInstance = Effect.flatMap(
EC2ClientInstanceConfig,
(config) => new EC2Client(config),
(config) =>
Effect.acquireRelease(
Effect.sync(() => new EC2Client(config)),
(client) => Effect.sync(() => client.destroy()),
),
);

/**
* @since 1.0.0
* @category layers
*/
export const EC2ClientInstanceLayer = Layer.effect(
export const EC2ClientInstanceLayer = Layer.scoped(
EC2ClientInstance,
makeEC2ClientInstance,
);
Expand Down
10 changes: 7 additions & 3 deletions packages/client-ecr/src/ECRClientInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ export class ECRClientInstance extends Context.Tag(
* @since 1.0.0
* @category constructors
*/
export const makeECRClientInstance = Effect.map(
export const makeECRClientInstance = Effect.flatMap(
ECRClientInstanceConfig,
(config) => new ECRClient(config),
(config) =>
Effect.acquireRelease(
Effect.sync(() => new ECRClient(config)),
(client) => Effect.sync(() => client.destroy()),
),
);

/**
* @since 1.0.0
* @category layers
*/
export const ECRClientInstanceLayer = Layer.effect(
export const ECRClientInstanceLayer = Layer.scoped(
ECRClientInstance,
makeECRClientInstance,
);
Expand Down
Loading

0 comments on commit b7a58d4

Please sign in to comment.