Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
feat: add ability to pin server to transaction state machine
Browse files Browse the repository at this point in the history
  • Loading branch information
daprahamian authored and mbroadst committed Feb 27, 2019
1 parent ebefb7b commit da13e55
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ class Transaction {

if (options.readConcern) this.options.readConcern = options.readConcern;
if (options.readPreference) this.options.readPreference = options.readPreference;

// TODO: This isn't technically necessary
this._pinnedServer = undefined;
}

get server() {
return this._pinnedServer;
}

/**
Expand All @@ -122,13 +129,26 @@ class Transaction {
const nextStates = stateMachine[this.state];
if (nextStates && nextStates.indexOf(nextState) !== -1) {
this.state = nextState;
if (this.state === TxnState.NO_TRANSACTION) {
this.unpinServer();
}
return;
}

throw new MongoError(
`Attempted illegal state transition from [${this.state}] to [${nextState}]`
);
}

pinServer(server) {
if (this.isActive) {
this._pinnedServer = server;
}
}

unpinServer() {
this._pinnedServer = undefined;
}
}

module.exports = { TxnState, Transaction };

0 comments on commit da13e55

Please sign in to comment.