Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bongnv/task
task is a simple Go library that helps to compose a complex business logic from smaller pieces in a maintainable way.
https://github.com/bongnv/task
Last synced: about 1 month ago
JSON representation
task is a simple Go library that helps to compose a complex business logic from smaller pieces in a maintainable way.
- Host: GitHub
- URL: https://github.com/bongnv/task
- Owner: bongnv
- License: mit
- Created: 2021-05-21T12:30:13.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-05-22T12:49:01.000Z (over 3 years ago)
- Last Synced: 2023-08-11T23:29:37.084Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# task
[![CI](https://github.com/bongnv/task/actions/workflows/ci.yml/badge.svg)](https://github.com/bongnv/task/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/bongnv/task/branch/main/graph/badge.svg?token=OpOoecFx9h)](https://codecov.io/gh/bongnv/task)
[![Go Report Card](https://goreportcard.com/badge/github.com/bongnv/task)](https://goreportcard.com/report/github.com/bongnv/task)`task` is a simple library that helps to compose complex business logic from smaller steps in a maintainable way.
## Quick Start
1. Make sure [Go](https://golang.org/) is installed and import `task` package to your project via the below command:
```sh
$ go get -u github.com/bongnv/task
```2. Import it to your code:
```go
import "github.com/bongnv/task"
```3. Use `task.Exec` to run multiple tasks in sequence:
```go
step1 := makeTask("Rinse the rice")
step2 := makeTask("Use the right ratio of water")
step3 := makeTask("Bring the water to a boil")
step4 := makeTask("Maintain a simmer")
step5 := makeTask("Cook without peeking or stirring")
step6 := makeTask("Let the rice rest covered")err := task.Exec(
ctx,
step1,
step2,
step3,
step4,
step5,
step6,
)
```## Usages
There are two ways to compose tasks together:
1. `task.Sequence` creates a new task by running multiple tasks in a sequence. It stops and returns error if any task returns error.
```go
composedTask := task.Sequence(
step1,
step2,
step3,
)
```
2. `task.Concurence` creates a new task by running multiple tasks concurrently. It stops, cancels the provided context and returns error if any task return error.```go
composedTask := task.Concurrence(
step1,
step2,
step3,
)
```