Noteworthy Placebo Mongers

    taskz

    3.0.0 • Public • Published

    Taskz

    Simple sequential and parallel task list runner for terminal.

    render1563366532786

    Install

    npm i taskz
    

    Getting started

    Create your task sequence then run it.

    const taskz = require("taskz");
     
    taskz([
      {
        text: "first task - sleeps for 200ms",
        task: async () => await new Promise(resolve => setTimeout(resolve, 200));
      },
      {
        text: "this task will fail",
        task: async () => {
          throw new Error("this task failed");
        }
      }
    ]).run();

    Usage

    Create tasks

    // Create tasks
    const myTasks = taskz([
      { text: "task 1", task: () => { /* ... */ } },
      { text: "task 2", task: () => { /* ... */ } }
    ]);
     
    // Run it
    myTasks.run()

    Subtasks

    Replace task by tasks and call taskz function.

    const myTasks = taskz([
      { text: "task 1", task: () => { /* ... */ } },
      {
        text: "task 2 with subtasks",
        tasks: taskz([
          { text: "task 2.1", task: () => { /* ... */ } },
          { text: "task 2.2", task: () => { /* ... */ } }
        ])
      }
    ]);

    Concurrent tasks (parallelism)

    Add { parallel: true } as a second parameter in taskz.

    const myTasks = taskz([
      { text: "task 1", task: () => { /* ... */ } },
      { text: "task 2", task: () => { /* ... */ } }
    ], { parallel: true });

    You can mix parallel and sequencial tasks within the same scenario via subtasks.

    Fail

    Fail and stop with stopOnError option. Does only work for sequencial tasks.

    const myTasks = taskz([
      {
        text: "this task will fail and stop",
        stopOnError: true,
        task: async () => {
          throw new Error("this task failed and stopped the whole process");
        }
      },
      { text: "this task will never be displayed", task: async () => {} }
    ]);

    Advanced Usage

    Use context

    const myTasks = taskz([
      {
        text: "task 1",
        task: ctx => { ctx.val = "foo" }
      },
      {
        text: "task 2",
        task: ctx => { doSomethingWith(ctx.val) }
      }
    ]);

    Change text within a task during execution

    const myTasks = taskz([
      {
        text: "my subtask 2",
        task: async (ctx, setText) => {
          setText("my subtask 2 foo");
          await new Promise(resolve => setTimeout(resolve, 200));
          setText(kleur.magenta("my subtask 2 bar");
        }
      }
    ]);

    Related

    • spinnies - Elegant terminal multiple spinners manager
    • cli-spinners - Spinners for use in the terminal
    • listr - Terminal task list (unmaintained)

    License

    MIT © rap2h

    Keywords

    none

    Install

    npm i taskz

    DownloadsWeekly Downloads

    4

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    25.7 kB

    Total Files

    9

    Last publish

    Collaborators

    • rap2hpoutre