Skip to content

Commit

Permalink
refactor(hexo/index): async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Dec 14, 2019
1 parent e4a5292 commit 62fdc49
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/hexo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Hexo {
});
}

init() {
async init() {
this.log.debug('Hexo version: %s', chalk.magenta(this.version));
this.log.debug('Working directory: %s', chalk.magenta(tildify(this.base_dir)));

Expand All @@ -224,14 +224,16 @@ class Hexo {
require('../plugins/tag')(this);

// Load config
return Promise.each([
await Promise.each([
'update_package', // Update package.json
'load_config', // Load config
'load_plugins' // Load external plugins & scripts
], name => require(`./${name}`)(this)).then(() => this.execFilter('after_init', null, {context: this})).then(() => {
// Ready to go!
this.emit('ready');
});
], name => require(`./${name}`)(this));

await this.execFilter('after_init', null, { context: this });

// Ready to go!
return await this.emit('ready');
}

call(name, args, callback) {
Expand Down Expand Up @@ -438,7 +440,7 @@ class Hexo {
});
}

exit(err) {
async exit(err) {
if (err) {
this.log.fatal(
{err},
Expand All @@ -447,9 +449,8 @@ class Hexo {
);
}

return this.execFilter('before_exit', null, {context: this}).then(() => {
this.emit('exit', err);
});
await this.execFilter('before_exit', null, { context: this });
return await this.emit('exit', err);
}

execFilter(type, data, options) {
Expand Down

0 comments on commit 62fdc49

Please sign in to comment.