Skip to content
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

Pass resolved result to the next task #126

Open
AhmedAtef07 opened this issue Dec 3, 2018 · 1 comment
Open

Pass resolved result to the next task #126

AhmedAtef07 opened this issue Dec 3, 2018 · 1 comment

Comments

@AhmedAtef07
Copy link

Hello,
I am using Listr as a way of pipelining, in which each task can send the resolved result to the next one.
The way I am doing it at the moment I assign a variable to context and keep changing it or assign different params, but, it would be much stronger if the returned value is used to be injected to the following task, as it will be very readable and defensive from code perspective.

new Listr([{
        title: 'task 1',
        task: () => {
            return Promise.resolve('pass to next task'),
    }, {
        title: 'task 2',
        task: (context, task, result?) => {
            const resultFromPreviousTask = ???
            return Promise.resolve();
        },
    }]).run()

We can either add special value to context (which will have some concerns) or we can return a new param to the callback (which will be weird to be the 3rd param).

@cschuff
Copy link

cschuff commented Dec 10, 2019

You could just write the result of task 1 into the context and access it from there in task 2:

new Listr([
	{
		title: 'Task 1',
		task: async (ctx) => {
                       // do stuff
                       const result = await myActualAsyncTask();
                       ctx.task1Result = result;
                },
	},
	{
		title: 'Task 2',
		task: ctx => console.log(ctx.task1Result),
	}
]).run();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants