Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kashifmin/chango
[WIP] A go package for running tasks, control concurreny, task completion and errors.
https://github.com/kashifmin/chango
Last synced: 6 days ago
JSON representation
[WIP] A go package for running tasks, control concurreny, task completion and errors.
- Host: GitHub
- URL: https://github.com/kashifmin/chango
- Owner: kashifmin
- Created: 2019-10-04T07:03:39.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-09T07:39:19.000Z (about 5 years ago)
- Last Synced: 2023-08-07T00:06:06.308Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# chango
A go package for running tasks concurrently and control concurreny, task completion and errors.# Examples
- Apply a function to items of a list concurrently
```go
func main() {list := []int{1, 2, 3, 4, 5, 6}
res := chango.Map(list, Square, &pkg.Options{Concurrency: 10})for i := range res {
fmt.Println(i.Result.(int))
}}
```- Apply a function to values recived from a channel
```go
func main() {list := []int{1, 2, 3, 4, 5, 6}
in := make(chan interface{}, 10)
for _, i := range list {
in <- i
}
close(in)
res2 := pkg.Pipe(
pkg.Pipe(in, Cube, &pkg.Options{Concurrency: 1}),
Square,
&pkg.Options{Concurrency: 1}
)
for i := range res2 {
fmt.Println(i.(int))
}
}
```
You can combine `Pipe` do some powerful stuff.
For example, you can do Map, Filter on the items in the channel concurrently!
NOTE: Remember to close the input channel once all items are sent, or else it will result in a deadlock.