Skip to content

Commit bc4be26

Browse files
committed
add declaration and mutualize state
1 parent e3a82d4 commit bc4be26

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ export interface ExecutionOptions {
188188

189189
getTimestamp(): number | Long | undefined | null;
190190

191+
setTimestamp(timestamp: number | Long | undefined | null): void;
192+
191193
setHints(hints: string[]): void;
192194
}
193195

lib/execution-options.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,23 @@ class ExecutionOptions {
289289

290290
/**
291291
* Gets the provided timestamp for the execution in microseconds from the unix epoch (00:00:00, January 1st, 1970).
292-
* <p>When a timestamp generator is used, this method returns <code>undefined</code>.</p>
293292
* @abstract
294293
* @returns {Number|Long|undefined|null}
295294
*/
296295
getTimestamp() {
297296

298297
}
299298

299+
/**
300+
* Sets the provided timestamp for the execution in microseconds from the unix epoch (00:00:00, January 1st, 1970).
301+
* @param {Number|Long|undefined|null} timestamp
302+
* @abstract
303+
* @ignore
304+
*/
305+
setTimestamp(timestamp) {
306+
307+
}
308+
300309
/**
301310
* @param {Array} hints
302311
* @abstract
@@ -376,6 +385,7 @@ class DefaultExecutionOptions extends ExecutionOptions {
376385
this._routingIndexes = this._queryOptions.routingIndexes;
377386
this._pageState = typeof this._queryOptions.pageState === 'string' ?
378387
utils.allocBufferFromString(this._queryOptions.pageState, 'hex') : this._queryOptions.pageState;
388+
this._timestamp = queryOptions.timestamp;
379389
this._preferredHost = null;
380390

381391
this._client = client;
@@ -498,10 +508,8 @@ class DefaultExecutionOptions extends ExecutionOptions {
498508
const generator = this._client.options.policies.timestampGeneration;
499509

500510
if ( types.protocolVersion.supportsTimestamp(this._client.controlConnection.protocolVersion) && generator) {
501-
if (this._generatedTimestamp === undefined) {
502-
this._generatedTimestamp = generator.next(this._client);
503-
}
504-
result = this._generatedTimestamp;
511+
result = generator.next(this._client);
512+
this.setTimestamp(result);
505513
} else {
506514
result = null;
507515
}
@@ -562,7 +570,11 @@ class DefaultExecutionOptions extends ExecutionOptions {
562570
}
563571

564572
getTimestamp() {
565-
return this._queryOptions.timestamp;
573+
return this._timestamp;
574+
}
575+
576+
setTimestamp(timestamp) {
577+
this._timestamp = timestamp;
566578
}
567579

568580
/**

0 commit comments

Comments
 (0)