concurrent

package
Version: v1.4.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package concurrent provide a helpers to setup, start and shutdown a lot of services in parallel.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(ctx Ctx, cancel func(), services ...func(Ctx) error) (err error)

Serve runs given services in parallel until either ctx.Done or any service exits, then it call cancel and wait until all services will exit.

Returns error of first service which returned non-nil error, if any.

func Setup

func Setup(ctx Ctx, vars map[interface{}]SetupFunc) error

Setup processes map which keys must be references to variables and values must be functions which returns values for these variables to run in parallel all functions which corresponding variables is nil.

     var a, b *int
	err = Setup(ctx, map[interface{}]SetupFunc{
		&a: setA,
		&b: setB,
	})

Returns first non-nil error returned by any of executed functions. It will panic if referenced variable can't be nil or corresponding function returns value which can't be assigned to that variable.

Types

type Ctx

type Ctx = context.Context

Ctx is a synonym for convenience.

type SetupFunc

type SetupFunc func(Ctx) (interface{}, error)

SetupFunc is described in Setup.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL