diff --git a/src/storages/base.spec.ts b/src/storages/base.spec.ts index 62f05db..a0627be 100644 --- a/src/storages/base.spec.ts +++ b/src/storages/base.spec.ts @@ -267,7 +267,7 @@ describe('BaseStorage', () => { const command = jest.fn(); testAdapter.getConnectionStatus = (): ConnectionStatus => ConnectionStatus.DISCONNECTED; - await expect((storage as any).cachedCommand(command, 1, 'hello')).resolves.toEqual(1); + await expect((storage as any).cachedCommand(command, 1, 'hello')).resolves.toEqual(undefined); expect(storage.commandsQueue).toEqual([{ fn: command, params: [1, 'hello' ]}]); }); diff --git a/src/storages/base.ts b/src/storages/base.ts index da6bbeb..a7a2609 100644 --- a/src/storages/base.ts +++ b/src/storages/base.ts @@ -121,7 +121,7 @@ export class BaseStorage implements Storage { public async touch(tags: string[]): Promise { await Promise.all([ this.cachedCommand(this.setTagVersions.bind(this), tags.map(tag => createTag(tag))), - this.deleteNotTouchedTags(tags) + this.cachedCommand(this.deleteNotTouchedTags.bind(this), tags) ]); } @@ -256,7 +256,7 @@ export class BaseStorage implements Storage { * 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. */ - private async cachedCommand(fn: CommandFn, ...args: any[]): Promise { + private async cachedCommand(fn: CommandFn, ...args: any[]): Promise { if (!fn) { throw new Error('Cached function is required'); } @@ -264,13 +264,13 @@ export class BaseStorage implements Storage { const connectionStatus = this.adapter.getConnectionStatus(); if (connectionStatus !== ConnectionStatus.CONNECTED) { - return this.commandsQueue.push({ + this.commandsQueue.push({ fn, params: args }); + } else { + await fn(...args); } - - return fn(...args); } /**