1 | import assert = require('assert');
|
2 | import types = require('../types');
|
3 | export = Config;
|
4 |
|
5 |
|
6 |
|
7 | class Config implements types.AsyncOptions {
|
8 |
|
9 |
|
10 | constructor(options?: types.AsyncOptions) {
|
11 | if (options) {
|
12 | this.returnValue = options.returnValue;
|
13 | this.acceptsCallback = options.acceptsCallback;
|
14 | this.isIterable = options.isIterable;
|
15 | this.maxConcurrency = options.maxConcurrency;
|
16 | }
|
17 | }
|
18 |
|
19 |
|
20 | returnValue: string = Config.PROMISE;
|
21 |
|
22 |
|
23 | acceptsCallback: boolean = false;
|
24 |
|
25 |
|
26 | isIterable: boolean = false;
|
27 |
|
28 |
|
29 | maxConcurrency: number = null;
|
30 |
|
31 |
|
32 | static PROMISE = 'promise';
|
33 | static THUNK = 'thunk';
|
34 | static RESULT = 'result';
|
35 | static NONE = 'none';
|
36 |
|
37 |
|
38 | validate() {
|
39 | var knownRetVal = [Config.PROMISE, Config.THUNK, Config.RESULT, Config.NONE].indexOf(this.returnValue) !== -1;
|
40 | assert(knownRetVal, 'Unrecognised return value: ' + this.returnValue);
|
41 |
|
42 | var hasNotifier = this.returnValue !== Config.NONE || this.acceptsCallback;
|
43 | assert(hasNotifier, 'At least one notification method must be enabled.');
|
44 | }
|
45 | }
|