Skip to content

Commit 6ad4c0c

Browse files
committed
initial commit, open source wait package
1 parent d929f63 commit 6ad4c0c

File tree

13 files changed

+760
-1
lines changed

13 files changed

+760
-1
lines changed

.github/dependabot.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
version: 2
3+
updates:
4+
- package-ecosystem: "gomod" # See documentation for possible values
5+
directory: "/" # Location of package manifests
6+
schedule:
7+
interval: "daily"
8+
reviewers:
9+
- muir
10+
- dncohen
11+
12+
- package-ecosystem: github-actions
13+
directory: "/"
14+
schedule:
15+
interval: "daily"
16+
reviewers:
17+
- muir
18+
- dncohen

.github/workflows/codecov.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Test and coverage
2+
3+
on: [push, pull_request]
4+
5+
permissions: # added using https://github.com/step-security/secure-workflows
6+
contents: read
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Harden Runner
13+
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481
14+
with:
15+
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
16+
17+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
18+
with:
19+
fetch-depth: 2
20+
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b
21+
with:
22+
go-version: '1.20'
23+
- name: Run coverage
24+
run: go test ./... -race -coverprofile=coverage.txt -covermode=atomic
25+
- name: Upload coverage to Codecov
26+
uses: codecov/[email protected]
27+
with:
28+
verbose: true
29+
env:
30+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ main ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ main ]
20+
schedule:
21+
- cron: '20 3 * * 4'
22+
23+
permissions: # added using https://github.com/step-security/secure-workflows
24+
contents: read
25+
26+
jobs:
27+
analyze:
28+
name: Analyze
29+
runs-on: ubuntu-latest
30+
permissions:
31+
actions: read
32+
contents: read
33+
security-events: write
34+
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
language: [ 'go' ]
39+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
40+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
41+
42+
steps:
43+
- name: Harden Runner
44+
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481
45+
with:
46+
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
47+
48+
- name: Checkout repository
49+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
50+
51+
# Initializes the CodeQL tools for scanning.
52+
- name: Initialize CodeQL
53+
uses: github/codeql-action/init@1b549b9259bda1cb5ddde3b41741a82a2d15a841
54+
with:
55+
languages: ${{ matrix.language }}
56+
# If you wish to specify custom queries, you can do so here or in a config file.
57+
# By default, queries listed here will override any specified in a config file.
58+
# Prefix the list here with "+" to use these queries and those in the config file.
59+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
60+
61+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
62+
# If this step fails, then you should remove it and run the build manually (see below)
63+
- name: Autobuild
64+
uses: github/codeql-action/autobuild@1b549b9259bda1cb5ddde3b41741a82a2d15a841
65+
66+
# ℹ️ Command-line programs to run using the OS shell.
67+
# 📚 https://git.io/JvXDl
68+
69+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
70+
# and modify them (or add more) to build your code if your project
71+
# uses a compiled language
72+
73+
#- run: |
74+
# make bootstrap
75+
# make release
76+
77+
- name: Perform CodeQL Analysis
78+
uses: github/codeql-action/analyze@1b549b9259bda1cb5ddde3b41741a82a2d15a841

.github/workflows/go.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
on: [push, pull_request]
2+
name: Unit Tests
3+
permissions: # added using https://github.com/step-security/secure-workflows
4+
contents: read
5+
6+
jobs:
7+
test:
8+
strategy:
9+
matrix:
10+
go-version: [1.20.x, 1.21.x, 1.22.x, 1.23.x]
11+
os: [ubuntu-latest, macos-latest, windows-latest]
12+
runs-on: ${{ matrix.os }}
13+
steps:
14+
- name: Harden Runner
15+
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481
16+
with:
17+
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
18+
19+
- name: Install Go
20+
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b
21+
with:
22+
go-version: ${{ matrix.go-version }}
23+
- name: Checkout code
24+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
25+
- name: Test
26+
run: go test ./...
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: golangci-lint
2+
on: [push]
3+
permissions: # added using https://github.com/step-security/secure-workflows
4+
contents: read
5+
6+
jobs:
7+
golangci:
8+
permissions:
9+
contents: read # for actions/checkout to fetch code
10+
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
11+
name: lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Harden Runner
15+
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481
16+
with:
17+
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
18+
19+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
20+
- name: golangci-lint
21+
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd
22+
with:
23+
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
24+
version: latest
25+
26+
# Optional: working directory, useful for monorepos
27+
# working-directory: somedir
28+
output: checkstyle
29+
30+
# Optional: golangci-lint command line arguments.
31+
# args: --issues-exit-code=0
32+
# args: --out-format checkstyle
33+
34+
# Optional: show only new issues if it's a pull request. The default value is `false`.
35+
# only-new-issues: true
36+
37+
# Optional: if set to true then the action will use pre-installed Go.
38+
# skip-go-installation: true
39+
40+
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
41+
# skip-pkg-cache: true
42+
43+
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
44+
# skip-build-cache: true

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2023 SingleStore, Inc
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# make formats, tests, and validates
2+
3+
4+
DOLLAR=$
5+
6+
all:
7+
git status | awk '/modified:/{print ${DOLLAR}NF}' | perl -n -e 'print if /\.go${DOLLAR}/' | xargs -r gofmt -w -s
8+
go mod tidy
9+
go test ./...
10+
golangci-lint run
11+
@ echo any output from the following command indicates an out-of-date direct dependency
12+
go list -u -m -f '{{if (and (not .Indirect) .Update)}}{{.}}{{end}}' all
13+
14+
misspell:;
15+
go install github.com/client9/misspell/cmd/misspell@latest
16+
misspell -w `find . -name \*.md`
17+

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
# wait
1+
# wait - wait for a condition to become true
2+
3+
[![GoDoc](https://godoc.org/github.com/singlestore-labs/wait?status.svg)](https://pkg.go.dev/github.com/singlestore-labs/wait)
4+
![unit tests](https://github.com/singlestore-labs/wait/actions/workflows/go.yml/badge.svg)
5+
[![report card](https://goreportcard.com/badge/github.com/singlestore-labs/wait)](https://goreportcard.com/report/github.com/singlestore-labs/wait)
6+
[![codecov](https://codecov.io/gh/singlestore-labs/wait/branch/main/graph/badge.svg)](https://codecov.io/gh/singlestore-labs/wait)
7+
8+
Install:
9+
10+
go get github.com/singlestore-labs/wait
11+
12+
---
13+
14+
Wait provides one function: `For`.
15+
16+
```go
17+
err := wait.For(func() (bool, error) {
18+
err := trySomething()
19+
if err != nil {
20+
if isFatal(err) {
21+
return false, err
22+
}
23+
return false, nil
24+
}
25+
return true, nil
26+
})
27+
```
28+
29+
It calls its function argument over and over until:
30+
31+
- a timeout occurs (failure)
32+
- the bool becomes true (success or failure depending on error)
33+
- if ExitOnError(true) and the error becomes non nil (failure)
34+
35+

0 commit comments

Comments
 (0)