go-async

module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2023 License: MIT

README

CI Lint Codecov

go-async

Repository that implements goroutines abstractions, making easy to run async code in Go.

Installation

go get github.com/f-amaral/go-async 

Features

Worker Pool

Creates a pool with a fixed number of workers that will execute the tasks sent to the pool.

package main

import (
	"encoding/json"
	"fmt"
	"github.com/f-amaral/go-async/pool"
)

func main() {
	inputSet := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

	exFunc := func(i int) (int, error) {
		return i * 2, nil
	}

	p := pool.NewPool(10, exFunc)
	defer p.Close()

	result := p.Process(inputSet)
	resultBytes, _ := json.Marshal(result)
	fmt.Println(string(resultBytes))
	// Error Handling:
	fmt.Println(result.GetErrors()) 
	
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL