Skip to content

Commit

Permalink
fixed linting
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinJWendt committed Jun 27, 2024
1 parent 5deb973 commit 174c299
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ linters-settings:
- d any
- data any
- n any
- t time.Time
- f func()
- cb func()
- t testing.T
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ It can run a function at a given time, in a given duration, or repeatedly at a g
## Index

- [type Task](<#Task>)
- [func After\(d time.Duration, task func\(\)\) \*Task](<#After>)
- [func After\(duration time.Duration, task func\(\)\) \*Task](<#After>)
- [func At\(t time.Time, task func\(\)\) \*Task](<#At>)
- [func Every\(interval time.Duration, task func\(\) bool\) \*Task](<#Every>)
- [func \(s \*Task\) ExecutesIn\(\) time.Duration](<#Task.ExecutesIn>)
Expand All @@ -102,7 +102,7 @@ type Task struct {
### func [After](<https://github.com/atomicgo/schedule/blob/main/schedule.go#L58>)

```go
func After(d time.Duration, task func()) *Task
func After(duration time.Duration, task func()) *Task
```

After executes the task after the given duration. The function is non\-blocking. If you want to wait for the task to be executed, use the Task.Wait method.
Expand Down Expand Up @@ -201,6 +201,7 @@ import (
func main() {
task := schedule.Every(time.Second, func() bool {
fmt.Println("1 second is over!")

return true // return false to stop the task
})

Expand Down
1 change: 1 addition & 0 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func ExampleAt() {
func ExampleEvery() {
task := schedule.Every(time.Second, func() bool {
fmt.Println("1 second is over!")

return true // return false to stop the task
})

Expand Down
9 changes: 6 additions & 3 deletions schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func (s *Task) Stop() {

// After executes the task after the given duration.
// The function is non-blocking. If you want to wait for the task to be executed, use the Task.Wait method.
func After(d time.Duration, task func()) *Task {
func After(duration time.Duration, task func()) *Task {
scheduler := newTask()
scheduler.nextExecution = time.Now().Add(d)
scheduler.nextExecution = time.Now().Add(duration)

go func() {
select {
case <-time.After(d):
case <-time.After(duration):
task()
scheduler.Stop()
case <-scheduler.stop:
Expand Down Expand Up @@ -104,9 +104,12 @@ func Every(interval time.Duration, task func() bool) *Task {
select {
case <-ticker.C:
task()

scheduler.nextExecution = time.Now().Add(interval)

case <-scheduler.stop:
ticker.Stop()

return
}
}
Expand Down

0 comments on commit 174c299

Please sign in to comment.