UNPKG

1.81 kBJavaScriptView Raw
1var assert = require('assert');
2/** A config object holds the configuration options for a variant of the async function. */
3var Config = (function () {
4 /** Construct a new Config instance. */
5 function Config(options) {
6 /** Recognised values: 'none', 'promise', 'thunk', 'result'. */
7 this.returnValue = Config.PROMISE;
8 /** Indicates whether a callback function, if supplied, will be used to notify waiters of results. */
9 this.acceptsCallback = false;
10 /** Indicates whether the suspendable function has iterator semantics or normal semantics. */
11 this.isIterable = false;
12 /** Indicates whether top-level concurrency should be limited to a specified ceiling. */
13 this.maxConcurrency = null;
14 if (options) {
15 this.returnValue = options.returnValue;
16 this.acceptsCallback = options.acceptsCallback;
17 this.isIterable = options.isIterable;
18 this.maxConcurrency = options.maxConcurrency;
19 }
20 }
21 /** Checks all configuration values and throw an error if anything is invalid. */
22 Config.prototype.validate = function () {
23 var knownRetVal = [Config.PROMISE, Config.THUNK, Config.RESULT, Config.NONE].indexOf(this.returnValue) !== -1;
24 assert(knownRetVal, 'Unrecognised return value: ' + this.returnValue);
25 var hasNotifier = this.returnValue !== Config.NONE || this.acceptsCallback;
26 assert(hasNotifier, 'At least one notification method must be enabled.');
27 };
28 // Constants for use with returnValue and callbackArg
29 Config.PROMISE = 'promise';
30 Config.THUNK = 'thunk';
31 Config.RESULT = 'result';
32 Config.NONE = 'none';
33 return Config;
34})();
35module.exports = Config;
36//# sourceMappingURL=config.js.map
\No newline at end of file