From 0f91ae62df8a37194fea84ce1efa9e733d9c1fd8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 21 Nov 2017 13:43:29 +0100 Subject: Add follow tests --- server/helpers/database-utils.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'server/helpers/database-utils.ts') diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index 169b80065..dacd747c9 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts @@ -4,12 +4,15 @@ import * as Bluebird from 'bluebird' import { logger } from './logger' type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[] } -function retryTransactionWrapper (functionToRetry: (...args) => Promise | Bluebird, options: RetryTransactionWrapperOptions) { +function retryTransactionWrapper ( + functionToRetry: (...args) => Promise | Bluebird, + options: RetryTransactionWrapperOptions +): Promise { const args = options.arguments ? options.arguments : [] - return transactionRetryer(callback => { + return transactionRetryer(callback => { functionToRetry.apply(this, args) - .then(result => callback(null, result)) + .then((result: T) => callback(null, result)) .catch(err => callback(err)) }) .catch(err => { @@ -18,8 +21,8 @@ function retryTransactionWrapper (functionToRetry: (...args) => Promise | B }) } -function transactionRetryer (func: Function) { - return new Promise((res, rej) => { +function transactionRetryer (func: (err: any, data: T) => any) { + return new Promise((res, rej) => { retry({ times: 5, -- cgit v1.2.3