Giter Club home page Giter Club logo

Comments (3)

cenk1cenk2 avatar cenk1cenk2 commented on June 10, 2024 1

No worries, thanks for the kind words.

Yes, the example was mostly about adding additional tasks while running. I mean it sounds different than I have understood it but, if you can manage to do this kind of state management in plain JavaScript then you might use Listr as the display tool.

RxJS kind of magic or promise-wrapping an event-emitter can also be good here since tasks also accept observables and you can always push data to an observable from anywhere. But I do not think this library alone would be the most perfect tool to handle this job. But showing for a not started task will not be possible in this case. Sorry just throwing in some ideas since I have failed to help in this case.

The key point here would be to not finish/finalize the task until it will not update the displaying status anymore.

You might achieve this easier with a custom implementation without this tool with something like log-update or stdout-update from npm.

from listr2.

cenk1cenk2 avatar cenk1cenk2 commented on June 10, 2024

Hey @marnixhoh,

Very interesting use case indeed. I do not think that there is currently a mechanism to rerun a given task since the tasks are marked as finalized after either they succeed, fail, or are skipped.

This can be achieved in a different manner though by adding tasks to the current running list by utilizing the Manager, but I have to add a new function for this to exactly work.

As I understand it initially you want to run all three tasks at the same time concurrently and depending on the outcome of a certain task let's say Process 3 you want to go ahead and re-run Process 1 again. If you can elaborate on that a little bit or whether my assumption is correct, I can try my best to help.

This can currently be achieved in some form like this where you can add dynamic tasks from a certain task. So you have to define your tasks outside of Listr as constants and run them in parallel first.

A mock code that is not valid and I have not tested:

const ctx = { task1Finished: new Promise() }
const manager = new Manager({ ctx })

const task1 =  {
    title: "Process 1 inactive",
    task: (ctx, task) => {
      task.title = "Process 1 building"
      task.title = "Process 1 active"

      ctx.task1Finished.resolve()
      // you have to also handle the failing case since if task 3 waits for the promise then it would be stuck
    }
}

manager.add([
  task1,
  {
    title: "Process 2 inactive",
    task: () => {
      task.title = "Process 2 building"
      task.title = "Process 2 active"
    }
  },
  {
    title: "Process 3 inactive",
    task: async (ctx) => {
      // if you need task 1 for this as i have understood
      await ctx.task1Finished

      task.title = "Process 3 building"
      task.title = "Process 3 active"

      manager.add([
          task1
      ])
    }
])

// i can add a exhaust method to `Manager` to do this while loop, because i will also need it soon
while (manager.tasks.length > 0) {
  await manager.runAll()
}

Visually I do not think it will be the same but yeah, I have intentionally disabled touching the task after it is finished due to some resource optimizations so the thing you might be asking for is in my eyes (if i understood correctly) possible.

Maybe another case is to implement a state management outside and use the retry property of tasks by throwing an error from the task.

from listr2.

marnixhoh avatar marnixhoh commented on June 10, 2024

Thank you so much for your incredibly quick reply! 😄

To elaborate a little bit on my use case:
I am working on a server, which manages processes. Ideally, the server would be able to send events to Listr. For example, when the server finishes building process 1, it would then send an event to Listr informing it that process 1 should now be marked as "completed". In other words, it would be great if the code could be running "outside" of Listr and push events to Listr as a way to visually inform the user.

The code you provided adds additional tasks right? As in it does not replace existing ones? If I'm correct here, then it would definitely be better than my current setup (which is just console.logging every status change 😆 ), but ideally I would like to "update" each task instead.

Again, thank you so much for your help here. It really does mean a lot. And even if Listr might not be the right tool to achieve this, I do want to let you know that it's a really cool and amazing tool to use :) Thanks a lot for maintaining it!

from listr2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.