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

Add spinner module #37

Merged
merged 2 commits into from
Nov 6, 2024
Merged

Add spinner module #37

merged 2 commits into from
Nov 6, 2024

Conversation

mvirgil
Copy link
Contributor

@mvirgil mvirgil commented Nov 5, 2024

Example usage:

        const spinner = createSpinner();
        spinner.start('Testing...');
        setTimeout(() => {
          spinner.interrupt(() => {
            console.log('Safely log during an active spinner using interrupt()');
          });
        }, 3000);
        setTimeout(() => {
          spinner.interrupt(() => {
            console.log('Safely log during an active spinner using interrupt() #2');
            console.error('Safely log during an active spinner using interrupt() #3');
          });
        }, 4000);
        setTimeout(() => {
          spinner.stop();
        }, 5000);
        setTimeout(() => {
          spinner.start('Reuse the same object');
        }, 6000);
        setTimeout(() => {
          spinner.stop();
          console.log('Done');
        }, 7000);

To use this with promises / async-await:

try {
  spinner.start('Waiting...');
  await someApiCall();
catch (e) {
  handleSomeError(e)
} finally {
  spinner.stop()
}
try {
  // some big try-catch
  spinner.start('with async...');
  await mockAsyncWork()
      .finally(() => spinner.stop());
  console.log('success!');
   // ...
} catch (e) {
   // ... normal error-handling code
}

We can add more helpers to this as-needed, in case we find it is clunky to use with our
actions and/or our logging needs. (Ex: expose something similar to oraPromise(), or a helper function to create a "spinner-aware" logger)

Uses the default "dots", though you can browse https://jsfiddle.net/sindresorhus/2eLtsbey/embedded/result/ which is a superset of what's available.

@mvirgil mvirgil requested a review from tonzhan2 November 5, 2024 00:59
@mvirgil mvirgil marked this pull request as ready for review November 6, 2024 17:04
@mvirgil mvirgil requested review from a team as code owners November 6, 2024 17:04
@mvirgil mvirgil merged commit e1e24e7 into main Nov 6, 2024
2 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 6, 2024
@mvirgil mvirgil deleted the spinner branch November 12, 2024 19:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants