coroutine

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 1 Imported by: 0

README

Coroutine

Usage

package main

import (
	"log"

	"github.com/go-kratos-ecosystem/components/v2/coroutine"
)

func main() {
	funcs := []func(){
		func() {
			log.Println("1")
		},
		func() {
			log.Println("2")
		},
		func() {
			log.Println("3")
		},
	}

	// Concurrent Example1
	c := coroutine.NewConcurrent(2)
	defer c.Close()
	c.Add(funcs...)

	c.Wait()

	// Concurrent Example2
	coroutine.RunConcurrent(2, funcs...)

	// Parallel Example1
	p := coroutine.NewParallel()
	p.Add(funcs...)
	p.Wait()

	// Parallel Example2
	coroutine.RunParallel(funcs...)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunConcurrent

func RunConcurrent(limit int, tasks ...func())

func RunParallel

func RunParallel(fs ...func())

Types

type Concurrent

type Concurrent struct {
	// contains filtered or unexported fields
}

func NewConcurrent

func NewConcurrent(limit int) *Concurrent

func (*Concurrent) Add

func (c *Concurrent) Add(fs ...func()) *Concurrent

func (*Concurrent) Close

func (c *Concurrent) Close()

func (*Concurrent) Wait

func (c *Concurrent) Wait()

type Parallel

type Parallel struct {
	// contains filtered or unexported fields
}

func NewParallel

func NewParallel() *Parallel

func (*Parallel) Add

func (p *Parallel) Add(fs ...func()) *Parallel

func (*Parallel) Wait

func (p *Parallel) Wait()

Jump to

Keyboard shortcuts

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