Generators instead of Observer?
franciscop opened this issue · 0 comments
franciscop commented
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);
});
}
}
]);