Skip to content
ts
import { delay, Listr } from 'listr2'

const tasks = new Listr(
  [
    {
      title: 'This task will execute.',
      task: (ctx, task): Listr =>
        task.newListr(
          [
            {
              title: 'This is a subtask.',
              task: async(): Promise<void> => {
                await delay(3000)
              }
            },
            {
              title: 'This is an another subtask.',
              task: async(): Promise<void> => {
                await delay(2000)
              }
            }
          ],
          { concurrent: true, rendererOptions: { collapseSubtasks: true } }
        )
    },

    {
      title: 'This task will execute.',
      task: (ctx, task): Listr =>
        task.newListr(
          [
            {
              title: 'This is a subtask.',
              task: async(): Promise<void> => {
                await delay(3000)
              }
            },
            {
              title: 'This is an another subtask.',
              task: async(): Promise<void> => {
                await delay(2000)
              }
            }
          ],
          { concurrent: false, rendererOptions: { collapseSubtasks: false } }
        )
    }
  ],
  { concurrent: false }
)

const ctx = await tasks.run()
Code Example

@code{4-} typescript{9,24,31,46,50}

Example

You can find the related examples here.

#257 v3.0.0+
Details