Skip to content

Commit

Permalink
Merge pull request #16 from alexkvak/feature/queue-delete-not-touched…
Browse files Browse the repository at this point in the history
…-tags-command

fix: Queue delete not touched tags command if adapter is not connected
  • Loading branch information
drwatsno authored Feb 12, 2020
2 parents a923085 + ce3c8f5 commit b37b837
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/storages/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]}]);
});

Expand Down
10 changes: 5 additions & 5 deletions src/storages/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class BaseStorage implements Storage {
public async touch(tags: string[]): Promise<void> {
await Promise.all([
this.cachedCommand(this.setTagVersions.bind(this), tags.map(tag => createTag(tag))),
this.deleteNotTouchedTags(tags)
this.cachedCommand(this.deleteNotTouchedTags.bind(this), tags)
]);
}

Expand Down Expand Up @@ -256,21 +256,21 @@ 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<any> {
private async cachedCommand(fn: CommandFn, ...args: any[]): Promise<void> {
if (!fn) {
throw new Error('Cached function is required');
}

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);
}

/**
Expand Down

0 comments on commit b37b837

Please sign in to comment.