-
-
Notifications
You must be signed in to change notification settings - Fork 944
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5acac2e
commit 9f4d820
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const uniqueExec = require('../vendor/unique'); | ||
|
||
export class Unique { | ||
// maximum time unique.exec will attempt to run before aborting | ||
maxTime: number = 10; | ||
|
||
// maximum retries unique.exec will recurse before aborting ( max loop depth ) | ||
maxRetries: number = 10; | ||
|
||
// time the script started | ||
// startTime: number = 0; | ||
|
||
constructor() { | ||
// Bind `this` so namespaced is working correctly | ||
for (const name of Object.getOwnPropertyNames(Unique.prototype)) { | ||
if (name === 'constructor' || typeof this[name] !== 'function') { | ||
continue; | ||
} | ||
this[name] = this[name].bind(this); | ||
} | ||
} | ||
|
||
/** | ||
* unique | ||
* | ||
* @method unique | ||
*/ | ||
unique( | ||
method: any, | ||
args: any, | ||
opts?: { | ||
startTime?: number; | ||
maxTime?: number; | ||
maxRetries?: number; | ||
currentIterations?: number; | ||
[key: string]: any; | ||
} | ||
): any { | ||
opts ||= {}; | ||
opts.startTime = new Date().getTime(); | ||
if (typeof opts.maxTime !== 'number') { | ||
opts.maxTime = this.maxTime; | ||
} | ||
if (typeof opts.maxRetries !== 'number') { | ||
opts.maxRetries = this.maxRetries; | ||
} | ||
opts.currentIterations = 0; | ||
return uniqueExec.exec(method, args, opts); | ||
} | ||
} |