-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from reugn/develop
v0.3.0
- Loading branch information
Showing
16 changed files
with
242 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
coverage: | ||
status: | ||
project: | ||
default: | ||
target: 80% | ||
patch: | ||
default: | ||
target: 70% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Build | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
go-version: [1.17.x] | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Run coverage | ||
run: go test . -coverprofile=coverage.out -covermode=atomic | ||
- name: Upload coverage to Codecov | ||
run: bash <(curl -s https://codecov.io/bash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: golangci-lint | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea/ | ||
.vscode/ | ||
/vendor | ||
coverage.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
run: | ||
skip-dirs: | ||
- generic | ||
|
||
linters: | ||
disable-all: true | ||
enable: | ||
- deadcode | ||
- dupl | ||
- errcheck | ||
- exportloopref | ||
- funlen | ||
- goconst | ||
- gocritic | ||
- gocyclo | ||
- gofmt | ||
- goimports | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- lll | ||
- misspell | ||
- prealloc | ||
- revive | ||
- staticcheck | ||
- structcheck | ||
- stylecheck | ||
- typecheck | ||
- unconvert | ||
- unparam | ||
- unused | ||
- varcheck | ||
|
||
issues: | ||
exclude-rules: | ||
# Exclude some linters from running on tests files. | ||
- path: _test\.go | ||
linters: | ||
- errcheck | ||
- unparam |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Go 1.18 Generics package | ||
This package contains preliminary [`Go Generics`](https://github.com/golang/go/issues/43651) prototypes. | ||
|
||
## Implemented data types | ||
* asyncTask <sup>[1](#unexported)</sup> | ||
|
||
<sup name="unexported">1</sup> Unexported since it is not possible to export generic code yet. | ||
|
||
## Getting started | ||
|
||
### Go 1.17 | ||
```sh | ||
go test ./... -gcflags=-G=3 -vet=off | ||
``` | ||
|
||
### Go 1.18+ | ||
Install [gotip](https://pkg.go.dev/golang.org/dl/gotip): | ||
```sh | ||
go install golang.org/dl/gotip@latest | ||
gotip download | ||
``` | ||
Use `gotip` to build and test the code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// go:build go1.18 | ||
|
||
package generic | ||
|
||
import ( | ||
"github.com/reugn/async" | ||
) | ||
|
||
// asyncTask is a data type for controlling possibly lazy & asynchronous computations. | ||
type asyncTask[T any] struct { | ||
taskFunc func() (T, error) | ||
} | ||
|
||
func newAsyncTask[T any](taskFunc func() (T, error)) *asyncTask[T] { | ||
return &asyncTask[T]{ | ||
taskFunc: taskFunc, | ||
} | ||
} | ||
|
||
func (task *asyncTask[T]) call() async.Future { | ||
promise := async.NewPromise() | ||
go func() { | ||
res, err := task.taskFunc() | ||
if err == nil { | ||
promise.Success(res) | ||
} else { | ||
promise.Failure(err) | ||
} | ||
}() | ||
return promise.Future() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// go:build go1.18 | ||
|
||
package generic | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/reugn/async/internal" | ||
) | ||
|
||
func TestAsyncTask(t *testing.T) { | ||
task := newAsyncTask[string](func() (string, error) { | ||
time.Sleep(1 * time.Second) | ||
return "ok", nil | ||
}) | ||
res, err := task.call().Get() | ||
|
||
internal.AssertEqual(t, "ok", res.(string)) | ||
internal.AssertEqual(t, err, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.