concurrency

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0, BSD-3-Clause, ISC, + 1 more Imports: 1 Imported by: 0

Documentation

Overview

Package concurrency implements a simple channel based ressource manager for concurrent operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ResourceManager

type ResourceManager[T any] struct {
	sync.WaitGroup
	Ressources chan T
	Errors     chan error
}

ResourceManager is a struct storing a channel of some given ressource (e.g. an [rlwe.Evaluator]) meant to be used concurrently and a channel for errors.

func NewRessourceManager

func NewRessourceManager[T any](ressources []T) *ResourceManager[T]

NewRessourceManager instantiates a new [RessourceManager].

func (*ResourceManager[T]) Run

func (r *ResourceManager[T]) Run(f Task[T])

Run runs a Task concurrently. If the internal error channel is not empty, does nothing. Adds any error returned by Task to the internal error channel.

func (*ResourceManager[T]) Wait

func (r *ResourceManager[T]) Wait() (err error)

Wait waits until all concurrent Task have finished and returns the first encountered error, if any.

type Task

type Task[T any] func(ressource T) (err error)

Task is an abstract templates for a function taking as input a ressource of any kind that can be used concurrently.

Jump to

Keyboard shortcuts

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