33 lines
735 B
Markdown
33 lines
735 B
Markdown
# cycle-scheduler
|
|
|
|
cycle-scheduler is a simple scheduler lib, handling tasks and executes them at regular interval. If a task is not in desired state, the task is re-scheduled with a backoff.
|
|
|
|
**NOTE**: this should be not used for long-running tasks, it's more suitable for shorts tasks like polling etc...
|
|
|
|
## Examples
|
|
* Init a new scheduler with 4 workers
|
|
```go
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
ctx := context.Background()
|
|
s := NewSchedulerCycle(ctx, 4)
|
|
|
|
// add a task
|
|
taskID := s.Delay(
|
|
func(ctx context.Context) (any, error) {
|
|
// execution
|
|
return any, nil
|
|
},
|
|
WithExecInterval(2*time.Millisecond)
|
|
)
|
|
|
|
<-ctx.Done()
|
|
<-s.Done()
|
|
```
|
|
|
|
**NOTE**: for `Delay` optionals arguments, check the `NewTask` method documentation for more details.
|
|
|
|
|