pax_global_header00006660000000000000000000000064146501253320014513gustar00rootroot0000000000000052 comment=ae3ed48951563f370fb02d881cf30dc5219b04cf golang-github-atomicgo-schedule-0.1.0/000077500000000000000000000000001465012533200176325ustar00rootroot00000000000000golang-github-atomicgo-schedule-0.1.0/.github/000077500000000000000000000000001465012533200211725ustar00rootroot00000000000000golang-github-atomicgo-schedule-0.1.0/.github/release.yml000066400000000000000000000005361465012533200233410ustar00rootroot00000000000000changelog: exclude: labels: - ignore-for-release authors: - octocat categories: - title: Breaking Changes 🛠 labels: - breaking - title: Exciting New Features 🎉 labels: - feature - title: Fixes 🔧 labels: - fix - title: Other Changes labels: - "*"golang-github-atomicgo-schedule-0.1.0/.github/settings.yml000066400000000000000000000016771465012533200235700ustar00rootroot00000000000000_extends: .github repository: # See https://developer.github.com/v3/repos/#edit for all available settings. # A short description of the repository that will show up on GitHub description: ⏰ Easily schedule non-blocking tasks in Go. Supports durations, specific times and intervals. # A comma-separated list of topics to set on the repository topics: atomicgo, go, golang, golang-library, scheduler, time, ticker, schedule, timer, hacktoberfest # Either `true` to make the repository private, or `false` to make it public. private: false # Either `true` to enable issues for this repository, `false` to disable them. has_issues: true # Either `true` to enable projects for this repository, or `false` to disable them. # If projects are disabled for the organization, passing `true` will cause an API error. has_projects: false # Either `true` to enable the wiki for this repository, `false` to disable it. has_wiki: false golang-github-atomicgo-schedule-0.1.0/.github/workflows/000077500000000000000000000000001465012533200232275ustar00rootroot00000000000000golang-github-atomicgo-schedule-0.1.0/.github/workflows/atomicgo.yml000066400000000000000000000005051465012533200255540ustar00rootroot00000000000000name: AtomicGo on: push: branches: [ main ] jobs: docs: if: "!contains(github.event.head_commit.message, 'autoupdate')" runs-on: ubuntu-latest steps: - name: Update Docs uses: atomicgo/ci@main env: ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} TERM: xterm-256color golang-github-atomicgo-schedule-0.1.0/.github/workflows/go.yml000066400000000000000000000013261465012533200243610ustar00rootroot00000000000000name: Go on: push: branches: [ main ] pull_request: jobs: build: name: Build runs-on: ${{ matrix.os }} strategy: matrix: os: [ ubuntu-latest, windows-latest, macos-latest ] steps: - name: Set up Go 1.x uses: actions/setup-go@v2 with: go-version: ^1 id: go - name: Check out code into the Go module directory uses: actions/checkout@v2 - name: Get dependencies run: go get -v -t -d ./... - name: Build run: go build -v . - name: Test run: go test -coverprofile="coverage.txt" -covermode=atomic -v -p 1 . - name: Upload coverage to Codecov uses: codecov/codecov-action@v1 golang-github-atomicgo-schedule-0.1.0/.github/workflows/lint.yml000066400000000000000000000006511465012533200247220ustar00rootroot00000000000000name: Code analysis on: [pull_request] jobs: golangci-lint: runs-on: ubuntu-latest steps: - name: Check out code into the Go module directory uses: actions/checkout@v3 with: fetch-depth: 0 - name: Linting with golangci-lint uses: reviewdog/action-golangci-lint@v2 with: github_token: ${{ secrets.ACCESS_TOKEN }} reporter: github-pr-review golang-github-atomicgo-schedule-0.1.0/.github/workflows/tweet-release.yml000066400000000000000000000016161465012533200265240ustar00rootroot00000000000000name: Tweet release # Listen to the `release` event on: release: types: [published] jobs: tweet: runs-on: ubuntu-latest steps: - uses: Eomm/why-don-t-you-tweet@v1 # We don't want to tweet if the repository is not a public one if: ${{ !github.event.repository.private }} with: tweet-message: "New ${{ github.event.repository.name }} release: ${{ github.event.release.tag_name }}! 🎉 Try it out: ${{ github.event.release.html_url }} #go #golang #opensource #library #release #atomicgo" env: TWITTER_CONSUMER_API_KEY: ${{ secrets.TWITTER_CONSUMER_API_KEY }} TWITTER_CONSUMER_API_SECRET: ${{ secrets.TWITTER_CONSUMER_API_SECRET }} TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} golang-github-atomicgo-schedule-0.1.0/.gitignore000066400000000000000000000007421465012533200216250ustar00rootroot00000000000000# Go template ## Binaries for programs and plugins *.exe *.exe~ *.dll *.so *.dylib ## Test binary, built with `go test -c` *.test ## Output of the go coverage tool, specifically when used with LiteIDE *.out ## Dependency directories (remove the comment below to include it) vendor/ # IDEs ## IntelliJ .idea *.iml out gen ## Visual Studio Code .vscode *.code-workspace # Operating System Files ## macOS ### General .DS_Store # Other ## Experimenting folder experimenting golang-github-atomicgo-schedule-0.1.0/.golangci.yml000066400000000000000000000032341465012533200222200ustar00rootroot00000000000000linters-settings: gocritic: enabled-tags: - diagnostic - experimental - opinionated - performance - style disabled-checks: - dupImport - ifElseChain - octalLiteral - whyNoLint - wrapperFunc - exitAfterDefer - hugeParam - ptrToRefParam - paramTypeCombine - unnamedResult linters: disable-all: true enable: # default linters - errcheck - gosimple - govet - ineffassign - staticcheck - typecheck - unused # additional linters - asasalint - asciicheck - bidichk - bodyclose - containedctx - contextcheck - decorder - dupl - durationcheck - errchkjson - errname - errorlint - exhaustive - exhaustruct - exportloopref - forcetypeassert - gocheckcompilerdirectives - gocritic - godot - godox - goerr113 - gofmt - goprintffuncname - gosec - gosmopolitan - importas - ireturn - nakedret - nestif - nilerr - nilnil - prealloc - predeclared - revive - rowserrcheck - tagalign - tenv - thelper - tparallel - unconvert - unparam - usestdlibvars - wastedassign - whitespace - wrapcheck - wsl - gocyclo - misspell issues: include: - EXC0012 - EXC0014 exclude-rules: - path: _test\.go linters: - gocyclo - errcheck - dupl - gosec - gocritic - linters: - gocritic text: "unnecessaryDefer:" - linters: - gocritic text: "preferDecodeRune:" service: golangci-lint-version: 1.53.x golang-github-atomicgo-schedule-0.1.0/LICENSE000066400000000000000000000020741465012533200206420ustar00rootroot00000000000000MIT License Copyright (c) 2022 Marvin Wendt (MarvinJWendt) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. golang-github-atomicgo-schedule-0.1.0/README.md000066400000000000000000000154201465012533200211130ustar00rootroot00000000000000

AtomicGo | schedule

Downloads Latest Release Tests Coverage Unit test count License: MIT Go report

---

Documentation | Contributing | Code of Conduct

---

AtomicGo

go get atomicgo.dev/schedule

# schedule ```go import "atomicgo.dev/schedule" ``` Package schedule provides a simple scheduler for Go. It can run a function at a given time, in a given duration, or repeatedly at a given interval. ## Index - [type Task](<#Task>) - [func After\(d 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>) - [func \(s \*Task\) IsActive\(\) bool](<#Task.IsActive>) - [func \(s \*Task\) NextExecutionTime\(\) time.Time](<#Task.NextExecutionTime>) - [func \(s \*Task\) StartedAt\(\) time.Time](<#Task.StartedAt>) - [func \(s \*Task\) Stop\(\)](<#Task.Stop>) - [func \(s \*Task\) Wait\(\)](<#Task.Wait>) ## type [Task]() Task holds information about the running task and can be used to stop running tasks. ```go type Task struct { // contains filtered or unexported fields } ``` ### func [After]() ```go func After(d 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.
Example

```go package main import ( "fmt" "time" "atomicgo.dev/schedule" ) func main() { task := schedule.After(5*time.Second, func() { fmt.Println("5 seconds are over!") }) fmt.Println("Some stuff happening...") task.Wait() } ```

### func [At]() ```go func At(t time.Time, task func()) *Task ``` At executes the task at the given time. The function is non\-blocking. If you want to wait for the task to be executed, use the Task.Wait method.
Example

```go package main import ( "fmt" "time" "atomicgo.dev/schedule" ) func main() { task := schedule.At(time.Now().Add(5*time.Second), func() { fmt.Println("5 seconds are over!") }) fmt.Println("Some stuff happening...") task.Wait() } ```

### func [Every]() ```go func Every(interval time.Duration, task func() bool) *Task ``` Every executes the task in the given interval, as long as the task function returns true. The function is non\-blocking. If you want to wait for the task to be executed, use the Task.Wait method.
Example

```go package main import ( "fmt" "time" "atomicgo.dev/schedule" ) func main() { task := schedule.Every(time.Second, func() bool { fmt.Println("1 second is over!") return true // return false to stop the task }) fmt.Println("Some stuff happening...") time.Sleep(10 * time.Second) task.Stop() } ```

### func \(\*Task\) [ExecutesIn]() ```go func (s *Task) ExecutesIn() time.Duration ``` ExecutesIn returns the duration until the next execution. ### func \(\*Task\) [IsActive]() ```go func (s *Task) IsActive() bool ``` IsActive returns true if the scheduler is active. ### func \(\*Task\) [NextExecutionTime]() ```go func (s *Task) NextExecutionTime() time.Time ``` NextExecutionTime returns the time when the next execution will happen. ### func \(\*Task\) [StartedAt]() ```go func (s *Task) StartedAt() time.Time ``` StartedAt returns the time when the scheduler was started. ### func \(\*Task\) [Stop]() ```go func (s *Task) Stop() ``` Stop stops the scheduler. ### func \(\*Task\) [Wait]() ```go func (s *Task) Wait() ``` Wait blocks until the scheduler is stopped. After and At will stop automatically after the task is executed. Generated by [gomarkdoc]() --- > [AtomicGo.dev](https://atomicgo.dev)  ·  > with ❤️ by [@MarvinJWendt](https://github.com/MarvinJWendt) | > [MarvinJWendt.com](https://marvinjwendt.com) golang-github-atomicgo-schedule-0.1.0/codecov.yml000066400000000000000000000002021465012533200217710ustar00rootroot00000000000000coverage: status: project: default: informational: true patch: default: informational: true golang-github-atomicgo-schedule-0.1.0/doc.go000066400000000000000000000002541465012533200207270ustar00rootroot00000000000000/* Package schedule provides a simple scheduler for Go. It can run a function at a given time, in a given duration, or repeatedly at a given interval. */ package schedule golang-github-atomicgo-schedule-0.1.0/examples_test.go000066400000000000000000000012371465012533200230410ustar00rootroot00000000000000package schedule_test import ( "fmt" "time" "atomicgo.dev/schedule" ) func ExampleAfter() { task := schedule.After(5*time.Second, func() { fmt.Println("5 seconds are over!") }) fmt.Println("Some stuff happening...") task.Wait() } func ExampleAt() { task := schedule.At(time.Now().Add(5*time.Second), func() { fmt.Println("5 seconds are over!") }) fmt.Println("Some stuff happening...") task.Wait() } func ExampleEvery() { task := schedule.Every(time.Second, func() bool { fmt.Println("1 second is over!") return true // return false to stop the task }) fmt.Println("Some stuff happening...") time.Sleep(10 * time.Second) task.Stop() } golang-github-atomicgo-schedule-0.1.0/go.mod000066400000000000000000000000461465012533200207400ustar00rootroot00000000000000module atomicgo.dev/schedule go 1.18 golang-github-atomicgo-schedule-0.1.0/go.sum000066400000000000000000000000001465012533200207530ustar00rootroot00000000000000golang-github-atomicgo-schedule-0.1.0/schedule.go000066400000000000000000000050051465012533200217550ustar00rootroot00000000000000package schedule import "time" // Task holds information about the running task and can be used to stop running tasks. type Task struct { stop chan struct{} nextExecution time.Time startedAt time.Time } // newTask creates a new Task. func newTask() *Task { return &Task{ stop: make(chan struct{}), startedAt: time.Now(), } } // StartedAt returns the time when the scheduler was started. func (s *Task) StartedAt() time.Time { return s.startedAt } // NextExecutionTime returns the time when the next execution will happen. func (s *Task) NextExecutionTime() time.Time { return s.nextExecution } // ExecutesIn returns the duration until the next execution. func (s *Task) ExecutesIn() time.Duration { return time.Until(s.nextExecution) } // IsActive returns true if the scheduler is active. func (s *Task) IsActive() bool { select { case <-s.stop: return false default: return true } } // Wait blocks until the scheduler is stopped. // After and At will stop automatically after the task is executed. func (s *Task) Wait() { <-s.stop } // Stop stops the scheduler. func (s *Task) Stop() { close(s.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 { scheduler := newTask() scheduler.nextExecution = time.Now().Add(d) go func() { select { case <-time.After(d): task() scheduler.Stop() case <-scheduler.stop: return } }() return scheduler } // At executes the task at the given time. // The function is non-blocking. If you want to wait for the task to be executed, use the Task.Wait method. func At(t time.Time, task func()) *Task { scheduler := newTask() scheduler.nextExecution = t go func() { select { case <-time.After(time.Until(t)): task() scheduler.Stop() case <-scheduler.stop: return } }() return scheduler } // Every executes the task in the given interval, as long as the task function returns true. // The function is non-blocking. If you want to wait for the task to be executed, use the Task.Wait method. func Every(interval time.Duration, task func() bool) *Task { scheduler := newTask() scheduler.nextExecution = time.Now().Add(interval) ticker := time.NewTicker(interval) go func() { for { select { case <-ticker.C: task() scheduler.nextExecution = time.Now().Add(interval) case <-scheduler.stop: ticker.Stop() return } } }() return scheduler }