Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ferranbt/periodic-dispatcher


https://github.com/ferranbt/periodic-dispatcher

Last synced: 10 days ago
JSON representation

Awesome Lists containing this project

README

        

# Periodic Dispatcher

Based on [Nomad](https://github.com/hashicorp/nomad) periodic dispatcher.

Launch multiple periodic jobs with a single thread.

```
package main

import (
"fmt"
"time"

"github.com/ferranbt/periodic-dispatcher"
)

type Job struct {
id string
}

func (j *Job) ID() string {
return j.id
}

func main() {
dispatcher := periodic.NewDispatcher()
dispatcher.SetEnabled(true)

dispatcher.Add(&Job{"a"}, 1*time.Second)
dispatcher.Add(&Job{"b"}, 2*time.Second)

for {
evnt := <-dispatcher.Events()
fmt.Println(evnt)
}
}
```