SamVerschueren / listr

Terminal task list
MIT License
3.29k stars 108 forks source link

Hangs after error when using Observable #120

Open unikitty37 opened 5 years ago

unikitty37 commented 5 years ago

Let me start out by saying that this is almost certainly something wrong with my code — but the README isn't providing any clues!

When I run the following, I expect to see

✔ good
✖ bad
   → nope
✔ ugly

but what I get is

 ✔ good
 ✖ bad
   ugly

with no spinner next to "ugly" — and it never exits.

    let taskList = []

    const files = ['good', 'bad', 'ugly']
    files.forEach(file => {
      taskList.push({
        title: file,
        exitOnError: false,
        task: () => new Observable(observer => {
          let progress = 0;
          let timer = setInterval(() => {
            if (progress < 100) {
              progress++;
              if (file === 'bad' && progress > 42) {
                observer.error('nope')
              }
              observer.next(`${progress}%`)
            } else {
              clearInterval(timer)
              observer.complete()
            }
          }, 30)
        })
      })
    })
    const tasks = new Listr(taskList)
    tasks.run().catch(err => {
      console.error(err)
    })

What could be going wrong — and is it possible to make the documentation on Observers a bit clearer?

For example, it doesn't actually mention how to throw an error in the Observable at all — the "Failure" example just returns Promise.reject straight off, and replacing the observer.error('nope') with return Promise.reject('nope') results in an infinite loop of UnhandledPromiseRejectionWarnings.

guyisra commented 5 years ago

did you manage to solve this?

unikitty37 commented 5 years ago

Afraid not — I ended up having to replace listr with ora in order to get the project working.