aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarak <[email protected]>2018-09-24 10:54:48 -0400
committerMarak <[email protected]>2018-09-24 10:55:08 -0400
commit4759e2b35c0557fbc17ed38dc5cbc21929de29bc (patch)
tree077dea345934ffb7c8f3fe3dc6ffded40115d96a /lib
parentafb8a7f2ac662ce742e18668d6537f0d42cba6e2 (diff)
downloadfaker-4759e2b35c0557fbc17ed38dc5cbc21929de29bc.tar.xz
faker-4759e2b35c0557fbc17ed38dc5cbc21929de29bc.zip
[api] [fix] [refactor] Unique options into class
* #466 #596 * Fixes scope issues with max values
Diffstat (limited to 'lib')
-rw-r--r--lib/unique.js26
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/unique.js b/lib/unique.js
index 4422a942..70d038fa 100644
--- a/lib/unique.js
+++ b/lib/unique.js
@@ -5,12 +5,34 @@ var uniqueExec = require('../vendor/unique');
*/
function Unique (faker) {
+ // initialize unique module class variables
+
+ // maximum time unique.exec will attempt to run before aborting
+ var maxTime = 10;
+
+ // maximum retries unique.exec will recurse before abortings ( max loop depth )
+ var maxRetries = 10;
+
+ // time the script started
+ // var startTime = 0;
+
/**
* unique
*
* @method unique
*/
- this.unique = uniqueExec.exec;
+ this.unique = function unique (method, args, opts) {
+ opts = opts || {};
+ opts.startTime = new Date().getTime();
+ if (typeof opts.maxTime !== 'number') {
+ opts.maxTime = maxTime;
+ }
+ if (typeof opts.maxRetries !== 'number') {
+ opts.maxRetries = maxRetries;
+ }
+ opts.currentIterations = 0;
+ return uniqueExec.exec(method, args, opts);
+ }
}
-module['exports'] = Unique;
+module['exports'] = Unique; \ No newline at end of file