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

Generators instead of Observer? #148

Open
franciscop opened this issue Jul 5, 2020 · 0 comments
Open

Generators instead of Observer? #148

franciscop opened this issue Jul 5, 2020 · 0 comments

Comments

@franciscop
Copy link

Hi Sam, I love this library and use it in some of my projects like happy and the experimental create-static-web. I am wondering if adding support for Generators has been considered? See this article intro, the user code could look like this:

const delay = time => new Promise(done => setTimeout(done, time));

const tasks = new Listr([
  {
    title: 'Success',
    task: async function* (){
      yield 'Foo';
      await delay(2000);
      yield 'Bar';
      await delay(2000);
    }
]);

Advantages:

  • No 3rd party library needed anymore
  • Simple and clean syntax
  • Async/await based

Disadvantages:

  • Some advanced flows might be more tricky than this simplified example

This example would behave the same as the one in the homepage:

const {Observable} = require('rxjs');

const tasks = new Listr([
  {
    title: 'Success',
    task: () => {
      return new Observable(observer => {
        observer.next('Foo');

        setTimeout(() => {
          observer.next('Bar');
        }, 2000);

        setTimeout(() => {
          observer.complete();
        }, 4000);
      });
    }
  }
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant