-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
Question: how to access task result from outside? #147
Comments
So, I made a new attempt to set variable values to the task context and try to access it from the outside, but I'm getting the error: I've just adapted the Original code: My adapted code - with changes highlighted in comments below: const list = new Listr([
{
title: 'foo',
task: () => Promise.resolve()
},
{
title: 'bar',
task: () => {
return new Listr([
{
title: 'unicorn',
task: () => Promise.reject(new Error('Unicorn failed'))
},
{
title: 'rainbow',
task: (ctx) => {
// CHANGE 1: set ctx property to be accessed from outside the task after the task finishes
ctx.myVariable = 'my value';
Promise.resolve();
}
}
], {
exitOnError: false // CHANGE 2: I need task `rainbow` to be executed regardless of `unicorn` failing
});
}
},
{
title: 'baz',
task: () => Promise.resolve()
}
], {
exitOnError: false // CHANGE 3: not sure if needed, but also tried setting it to `true`
});
try {
// CHANGE 4: attempt to access the value of `myVariable` that I expected to be in the `ctx`/task result
const { myVariable: listResult } = await list.run().catch(error => { });
console.log('list result', listResult);
} catch (error) {
console.log('Task list failed', error);
} The above code outputs: What am I doing wrong? |
I guess you can chain off a list.run()
.catch(error => { /* … */ })
.then(ctx => {
console.log(ctx.myVariable)
}) Don't know if you can achieve this with |
Turns out it can work with You should be able to do this but just try {
const { myVariable: listResult } = await list.run();
console.log('list result', listResult);
} catch (error) {
console.log('Task list failed', error);
} |
Use listr2 https://github.com/cenk1cenk2/listr2 👍 |
Hi,
Couldn't find in the docs a way to access the result of a task after the task is finished.
Example code that I tried without success:
Is there any way to access the task result
remoteItens
value after the task has finished?The text was updated successfully, but these errors were encountered: