Comparing version 1.5.1 to 1.6.0
@@ -0,1 +1,8 @@ | ||
# [1.6.0](https://github.com/TinkoffCreditSystems/cachalot/compare/v1.5.1...v1.6.0) (2020-02-14) | ||
### Features | ||
* Queue "cached" commands if its execution timed out ([b024999](https://github.com/TinkoffCreditSystems/cachalot/commit/b024999)) | ||
## [1.5.1](https://github.com/TinkoffCreditSystems/cachalot/compare/v1.5.0...v1.5.1) (2020-02-12) | ||
@@ -2,0 +9,0 @@ |
@@ -5,1 +5,2 @@ export declare function ParseError(error: Error): Error; | ||
export declare function OperationTimeoutError(timeout: number): Error; | ||
export declare function isOperationTimeoutError(error: any): boolean; |
@@ -27,2 +27,6 @@ "use strict"; | ||
exports.OperationTimeoutError = OperationTimeoutError; | ||
function isOperationTimeoutError(error) { | ||
return error instanceof Error && error.name === constants_1.ERRORS.OperationTimeoutError; | ||
} | ||
exports.isOperationTimeoutError = isOperationTimeoutError; | ||
//# sourceMappingURL=errors.js.map |
@@ -20,3 +20,3 @@ import { ConnectionStatus } from '../connection-status'; | ||
fn: CommandFn; | ||
params: any; | ||
params: any[]; | ||
} | ||
@@ -125,5 +125,7 @@ /** | ||
* All commands wrapped with this method will be "cached". This means that if there are problems with the connection | ||
* the response will be sent immediately and the command will be executed later when the connection is restored. | ||
* the response will be sent immediately and the command will be executed later when the connection is restored | ||
* or current execution timed out. | ||
*/ | ||
private cachedCommand; | ||
private queueCommand; | ||
/** | ||
@@ -130,0 +132,0 @@ * Saves only new not touched tags in tag storage. |
@@ -11,2 +11,3 @@ "use strict"; | ||
const deserialize_1 = __importDefault(require("../deserialize")); | ||
const errors_1 = require("../errors"); | ||
const record_1 = __importDefault(require("../record")); | ||
@@ -177,3 +178,4 @@ const create_tag_1 = __importDefault(require("../record/create-tag")); | ||
* All commands wrapped with this method will be "cached". This means that if there are problems with the connection | ||
* the response will be sent immediately and the command will be executed later when the connection is restored. | ||
* the response will be sent immediately and the command will be executed later when the connection is restored | ||
* or current execution timed out. | ||
*/ | ||
@@ -186,11 +188,21 @@ async cachedCommand(fn, ...args) { | ||
if (connectionStatus !== connection_status_1.ConnectionStatus.CONNECTED) { | ||
this.commandsQueue.push({ | ||
fn, | ||
params: args | ||
}); | ||
this.queueCommand(fn, args); | ||
} | ||
else { | ||
await fn(...args); | ||
try { | ||
await fn(...args); | ||
} | ||
catch (error) { | ||
if (errors_1.isOperationTimeoutError(error)) { | ||
this.queueCommand(fn, args); | ||
} | ||
else { | ||
throw error; | ||
} | ||
} | ||
} | ||
} | ||
queueCommand(fn, params) { | ||
this.commandsQueue.push({ fn, params }); | ||
} | ||
/** | ||
@@ -197,0 +209,0 @@ * Saves only new not touched tags in tag storage. |
{ | ||
"name": "cachalot", | ||
"version": "1.5.1", | ||
"version": "1.6.0", | ||
"description": "Cache manager for nodejs with support different cache strategies", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
131777
1848