зеркало из https://github.com/Azure/go-asynctask.git
tweaks
This commit is contained in:
Родитель
34788908e3
Коммит
45624be244
|
@ -7,6 +7,14 @@
|
|||
|
||||
Simple mimik of async/await for those come from C# world, so you don't need to dealing with waitGroup/channel in golang.
|
||||
|
||||
also the result is strongTyped with go generics, no type assertion is needed.
|
||||
|
||||
few chaining method provided:
|
||||
- ContinueWith: send task1's output to task2 as input, return reference to task2.
|
||||
- AfterBoth : send output of taskA, taskB to taskC as input, return reference to taskC.
|
||||
- WaitAll: all of the task have to finish to end the wait (with an option to fail early if any task failed)
|
||||
- WaitAny: any of the task finish would end the wait
|
||||
|
||||
```golang
|
||||
// start task
|
||||
task := asynctask.Start(ctx, countingTask)
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/go-asynctask/v2"
|
||||
"github.com/Azure/go-asynctask"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/go-asynctask/v2"
|
||||
"github.com/Azure/go-asynctask"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/go-asynctask/v2"
|
||||
"github.com/Azure/go-asynctask"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
2
go.mod
2
go.mod
|
@ -1,4 +1,4 @@
|
|||
module github.com/Azure/go-asynctask/v2
|
||||
module github.com/Azure/go-asynctask
|
||||
|
||||
go 1.20
|
||||
|
||||
|
|
4
task.go
4
task.go
|
@ -14,8 +14,8 @@ type AsyncFunc[T any] func(context.Context) (T, error)
|
|||
// ActionToFunc convert a Action to Func (C# term), to satisfy the AsyncFunc interface.
|
||||
// - Action is function that runs without return anything
|
||||
// - Func is function that runs and return something
|
||||
func ActionToFunc(action func(context.Context) error) func(context.Context) (*interface{}, error) {
|
||||
return func(ctx context.Context) (*interface{}, error) {
|
||||
func ActionToFunc(action func(context.Context) error) func(context.Context) (interface{}, error) {
|
||||
return func(ctx context.Context) (interface{}, error) {
|
||||
return nil, action(ctx)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/go-asynctask/v2"
|
||||
"github.com/Azure/go-asynctask"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/go-asynctask/v2"
|
||||
"github.com/Azure/go-asynctask"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/go-asynctask/v2"
|
||||
"github.com/Azure/go-asynctask"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче