Comments (3)
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.
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.
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)
- [Feature]: Support of Inquirer HOT 6
- [Support]: Query/Inspect data in ProcessOutputBuffer HOT 4
- [Feature]: Do not render the followup (future) tasks during execution and in case of an error HOT 3
- [Support]: How do i signal that root task is failed after returning newListr with a list of subtasks? HOT 4
- [Bug]: Task run finished should return task return value HOT 1
- [Bug]: `persistentOutput` with output streaming HOT 1
- [Feature]: consider supporting the node14 version? HOT 4
- [Feature]: Multiline output for DefaultRenderer HOT 1
- [Bug]: disableColor option is ignored HOT 4
- [Bug]: Documentation site broken HOT 3
- [Bug]: SyntaxError: Unexpected token '??=' HOT 1
- [Bug]: TypeError: Cannot read properties of undefined (reading 'collapseSubtasks') HOT 5
- [Support]: How to use node-schedule? HOT 4
- [Support]: How to handle nested listr2 HOT 3
- [Support]: How to pin an output? HOT 4
- [Bug]: SimpleRenderer should not invoke process.release HOT 5
- [Support]: Is there a way to clear output per task? HOT 3
- [Bug]: Doc site broken HOT 5
- [Bug]: `rxjs` is imported in the exported typescript definition but is declared as a dev dependency HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from listr2.