diff --git a/dev/src/index.ts b/dev/src/index.ts index 9cf3a8483..1bf31be98 100644 --- a/dev/src/index.ts +++ b/dev/src/index.ts @@ -137,6 +137,11 @@ const CLOUD_RESOURCE_HEADER = 'google-cloud-resource-prefix'; */ export const MAX_REQUEST_RETRIES = 5; +/*! + * The maximum number of times to attempt a transaction before failing. + */ +export const DEFAULT_MAX_TRANSACTION_ATTEMPTS = 5; + /*! * The default number of idle GRPC channel to keep. */ @@ -994,10 +999,9 @@ export class Firestore implements firestore.Firestore { ): Promise { validateFunction('updateFunction', updateFunction); - const defaultAttempts = 5; const tag = requestTag(); - let maxAttempts: number; + let maxAttempts = DEFAULT_MAX_TRANSACTION_ATTEMPTS; if (transactionOptions) { validateObject('transactionOptions', transactionOptions); @@ -1006,9 +1010,8 @@ export class Firestore implements firestore.Firestore { transactionOptions.maxAttempts, {optional: true, minValue: 1} ); - maxAttempts = transactionOptions.maxAttempts || defaultAttempts; - } else { - maxAttempts = defaultAttempts; + maxAttempts = + transactionOptions.maxAttempts || DEFAULT_MAX_TRANSACTION_ATTEMPTS; } const transaction = new Transaction(this, tag);