Im having trouble to understand the following javascript code:
/**
* Outputs the result of compiling a template.
*
* @module generator.generate
* @param {Object} config Configuration options
* @param {Object|String} config.asyncapi AsyncAPI JSON or a string pointing to an AsyncAPI file.
* @param {String} config.target_dir Path to the directory where the files will be generated.
* @return {Promise}
*/
generator.generate = config => new Promise((resolve, reject) => {
bundleAndApplyDefaults(config)
.then((cfg) => {
async function start () {
await registerHelpers(cfg);
await registerPartials(cfg);
await generateDirectoryStructure(cfg);
}
start().then(resolve).catch(reject);
})
.catch(reject);
});
More specifically in which order the .then
's are called and what promise they belong to. I think that the first .then
gets called when the method bundleAndApplyDefaults(config)
is completed. But im not sure what where the parameter cfg
comes from.
Inside the function start()
gets called and the second .then
with the resolve of the original promise gets executed, the original promise only has .catch(reject) outside the executor and no .then
for success, as far as i know.
Hereby im also not sure, why there is a .then
after the start method, when theres no actual promise.
I appreciate any help.