@mstuercke/api-utils 5.2.2 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mstuercke/api-utils",
3
- "version": "5.2.2",
3
+ "version": "6.0.0",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -1,6 +1,6 @@
1
1
  import {PostToConnectionCommand} from '@aws-sdk/client-apigatewaymanagementapi';
2
2
  import {AnyTRPCRouter, callTRPCProcedure, inferRouterContext} from '@trpc/server';
3
- import {APIGatewayProxyEvent, APIGatewayProxyResult} from 'aws-lambda';
3
+ import {APIGatewayProxyEvent, APIGatewayProxyResult, Context} from 'aws-lambda';
4
4
  import {getApiGatewayManagementApiClient} from '../getApiGatewayManagementApiClient';
5
5
  import {getConnection} from '../getConnection';
6
6
  import {TrpcSubscriptionRequest} from './TrpcSubscriptionRequest';
@@ -13,7 +13,8 @@ export const awsLambdaTrpcSubscriptionRequestHandler = <Router extends AnyTRPCRo
13
13
  }) => {
14
14
  const {router, createContext} = opts;
15
15
 
16
- return async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
16
+ return async (event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> => {
17
+ context.callbackWaitsForEmptyEventLoop = false;
17
18
  const connection = getConnection(event);
18
19
 
19
20
  if (!event.body || event.body === '[]')
@@ -89,6 +90,8 @@ export const awsLambdaTrpcSubscriptionRequestHandler = <Router extends AnyTRPCRo
89
90
 
90
91
  let stopped = false;
91
92
  while (!stopped) {
93
+ if (messageQueue.length === 0)
94
+ await new Promise(resolve => setTimeout(resolve, 10));
92
95
  const message = messageQueue.shift();
93
96
  if (!message)
94
97
  continue;