Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ITcathyh/conexec
A concurrent toolkit to help execute funcs concurrently in an efficient and safe way. It supports specifying the overall timeout to avoid blocking.
https://github.com/ITcathyh/conexec
go golang goroutine
Last synced: 14 days ago
JSON representation
A concurrent toolkit to help execute funcs concurrently in an efficient and safe way. It supports specifying the overall timeout to avoid blocking.
- Host: GitHub
- URL: https://github.com/ITcathyh/conexec
- Owner: ITcathyh
- License: bsd-2-clause
- Created: 2019-12-24T07:35:11.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-28T03:09:55.000Z (over 4 years ago)
- Last Synced: 2024-07-31T20:51:51.548Z (3 months ago)
- Topics: go, golang, goroutine
- Language: Go
- Homepage:
- Size: 42 KB
- Stars: 15
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-go - conexec - A concurrent toolkit to help execute funcs concurrently in an efficient and safe way. It supports specifying the overall timeout to avoid blocking and uses goroutine pool to improve efficiency. (Goroutines / Search and Analytic Databases)
- awesome-go-extra - conexec - 12-24T07:35:11Z|2020-06-28T03:09:55Z| (Goroutines / Advanced Console UIs)
README
## Introduction
[![Build Status](https://travis-ci.org/ITcathyh/conexec.svg?branch=master)](https://travis-ci.org/ITcathyh/conexec)
[![codecov](https://codecov.io/gh/ITcathyh/conexec/branch/master/graph/badge.svg)](https://codecov.io/gh/ITcathyh/conexec)
[![Go Report Card](https://goreportcard.com/badge/github.com/ITcathyh/conexec)](https://goreportcard.com/report/github.com/ITcathyh/conexec)
[![GoDoc](https://godoc.org/github.com/ITcathyh/conexec?status.svg)](https://godoc.org/github.com/ITcathyh/conexec)conexec is a concurrent toolkit to help execute functions concurrently in an efficient and safe way. It supports specifying the overall timeout to avoid blocking.
## How to use
Generally it can be set as a singleton to save memory. There are some example to use it.
### Normal Actuator
Actuator is a base struct to execute functions concurrently.
```
opt := &Options{TimeOut:DurationPtr(time.Millisecond*50)}
c := NewActuator(opt)
err := c.Exec(
func() error {
fmt.Println(1)
time.Sleep(time.Second * 2)
return nil
},
func() error {
fmt.Println(2)
return nil
},
func() error {
time.Sleep(time.Second * 1)
fmt.Println(3)
return nil
},
)
if err != nil {
// ...do sth
}
```
### Pooled Actuator
Pooled actuator uses the goroutine pool to execute functions. In some times it is a more efficient way.
```
opt := &Options{TimeOut:DurationPtr(time.Millisecond*50)}
c := NewPooledActuator(5, opt)
err := c.Exec(...)
if err != nil {
// ...do sth
}
```
Use custom goroutine pool
```
c := NewPooledActuator(5).WithPool(pool)
```
### Simply exec using goroutine
```
done := Exec(...)if !done {
// ... do sth
}
```