MCPcopy Create free account
hub / github.com/node-config/node-config / deferConfig

Function deferConfig

lib/defer.js:36–67  ·  view source on GitHub ↗

* Accept a function that we will execute later and return a deferred placeholder. * * @template TOriginal * @template TResult * @param {(this: Config, config: Config, original: TOriginal) => TResult | Promise } func * @returns {DeferredConfig}

(func)

Source from the content-addressed store, hash-verified

34 * @returns {DeferredConfig}
35 */
36function deferConfig(func) {
37 /** @type {DeferredConfig} */
38 const obj = Object.create(DeferredConfig.prototype);
39 obj.prepare = function(config, prop, property) {
40 const original = prop[property]._original;
41
42 if (isAsyncFunction(func)) {
43 obj.resolve = async function () {
44 const promise = func.call(config, config, original);
45
46 Object.defineProperty(prop, property, { value: promise });
47 Object.defineProperty(prop, property, { value: await promise });
48
49 return promise;
50 }
51 } else {
52 obj.resolve = function() {
53 const value = func.call(config, config, original);
54
55 Object.defineProperty(prop, property, {value: value});
56
57 return value;
58 };
59 }
60
61 Object.defineProperty(prop, property, { get: function() { return obj.resolve(); } });
62
63 return obj;
64 };
65
66 return obj;
67}
68
69export { deferConfig, DeferredConfig };

Callers 2

0-util.jsFile · 0.90
defer.tsFile · 0.90

Calls 1

resolveMethod · 0.80

Tested by

no test coverage detected