Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Way faster without spinner #490

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 4 additions & 27 deletions lib/tldr.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const sample = require('lodash/sample');
const fs = require('fs-extra');
const ms = require('ms');
const ora = require('ora');
const { EmptyCacheError, MissingPageError, MissingRenderPathError } = require('./errors');
const Cache = require('./cache');
const search = require('./search');
Expand Down Expand Up @@ -90,15 +89,11 @@ class Tldr {
}

updateCache() {
return spinningPromise('Updating...', () => {
return this.cache.update();
});
return this.cache.update();
}

updateIndex() {
return spinningPromise('Creating index...', () => {
return search.createIndex();
});
return search.createIndex();
}

search(keywords) {
Expand Down Expand Up @@ -131,13 +126,9 @@ class Tldr {
if (this.config.skipUpdateWhenPageNotFound === true) {
return '';
}
return spinningPromise('Page not found. Updating cache...', () => {
return this.cache.update();
})
return this.cache.update()
.then(() => {
return spinningPromise('Creating index...', () => {
return search.createIndex();
});
return search.createIndex();
})
.then(() => {
// And then, try to check in cache again
Expand Down Expand Up @@ -181,18 +172,4 @@ class Tldr {
}
}

function spinningPromise(text, factory) {
const spinner = ora();
spinner.start(text);
return factory()
.then((val) => {
spinner.succeed();
return val;
})
.catch((err) => {
spinner.fail();
throw err;
});
}

module.exports = Tldr;
Loading
Loading