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 8a0422a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 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
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 8a0422a

Please sign in to comment.