Add typing for module bluebird-retry

This commit is contained in:
Pascal Vomhoff
2015-09-04 18:17:09 +02:00
parent d9fea91e84
commit fcc97a5d06
2 changed files with 59 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
/// <reference path="bluebird-retry.d.ts" />
/// <reference path="../bluebird/bluebird.d.ts" />
import Promise = require('bluebird');
import retry = require('bluebird-retry');
function promiseSuccess(text:string) {
return Promise.resolve(text);
};
var count = 0;
function myfunc() {
console.log('myfunc called ' + (++count) + ' times');
if (count < 3) {
throw new Error('i fail the first two times');
} else {
return promiseSuccess('i succeed the third time');
}
}
retry(myfunc)
.done(function(result) { console.log(result); } );
//Options example
function logFail() {
console.log(new Date().toISOString());
throw new Error('bail');
}
var options:retry.Options = {
max_tries: 4,
interval: 500
};
retry(logFail, options);
+24
View File
@@ -0,0 +1,24 @@
// Type definitions for bluebird-retry
// Project: https://github.com/jut-io/bluebird-retry
// Definitions by: Pascal Vomhoff <https://github.com/pvomhoff>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../bluebird/bluebird.d.ts" />
declare module "bluebird-retry" {
import Promise = require('bluebird');
function retry<T>(func:(param:T)=>void, options?:retry.Options):Promise<T>;
module retry {
export interface Options {
interval?:number;
backoff?:number;
max_interval?:number;
timeout?:number;
max_tries?:number;
}
}
export = retry;
}