> ## Documentation Index
> Fetch the complete documentation index at: https://ziva.zeleza.ru/llms.txt
> Use this file to discover all available pages before exploring further.

# FuncTask

> Function execution task with progress display

# FuncTask

`FuncTask` allows execution of arbitrary functions with progress display and results.

## Creating

```go theme={null}
task := ziva.NewFuncTask("Processing", func() error {
    // perform work
    time.Sleep(2 * time.Second)
    return nil
})
```

## Configuration Options

```go theme={null}
task := ziva.NewFuncTask(
    "Data Loading",
    processFunc,
    ziva.WithSummaryFunction(func() []string {
        return []string{"Processed: 100 files"}
    }),
    ziva.WithStopOnError(true), // stop queue on error
)
```

### Controlling the completion label

By default a completed `FuncTask` renders a “DONE” badge on the right.

```go theme={null}
task := ziva.NewFuncTask("Build", build).
    WithSuccessLabel("FINISHED") // custom text
```

Hide the badge completely when it is not needed:

```go theme={null}
task := ziva.NewFuncTask("Background setup", prepare).
    WithoutSuccessLabel()
```

You can achieve the same result with functional options passed to the constructor:

```go theme={null}
task := ziva.NewFuncTask(
    "Import data",
    importData,
    ziva.WithoutSuccessLabelOption(),       // disable the badge
    ziva.WithSummaryFunction(renderSummary),
)
```

Later you may re-enable the badge with `WithSuccessLabelEnabled(true)` or swap the text using `WithSuccessLabel(...)`.

## Example with Report

```go theme={null}
var stats struct {
    Processed int
    Errors    int
}

task := ziva.NewFuncTask(
    "File Processing",
    func() error {
        for i := 0; i < 100; i++ {
            time.Sleep(50 * time.Millisecond)
            stats.Processed++
            if rand.Intn(20) == 0 {
                stats.Errors++
            }
        }
        return nil
    },
    ziva.WithSummaryFunction(func() []string {
        return []string{
            fmt.Sprintf("Processed: %d", stats.Processed),
            fmt.Sprintf("Errors: %d", stats.Errors),
        }
    }),
)

queue := ziva.NewQueue("Batch Processing")
queue.AddTasks(task)
queue.Run()
```
