g

package
v0.0.0-...-67aea11 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Example
package main

import (
	"fmt"

	g "github.com/eric2918/leaf-cluster/go"
)

func main() {
	d := g.New(10)

	// go 1
	var res int
	d.Go(func() {
		fmt.Println("1 + 1 = ?")
		res = 1 + 1
	}, func() {
		fmt.Println(res)
	})

	d.Cb(<-d.ChanCb)

	// go 2
	d.Go(func() {
		fmt.Print("My name is ")
	}, func() {
		fmt.Println("Leaf")
	})

	d.Close()

}
Output:

1 + 1 = ?
2
My name is Leaf

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Go

type Go struct {
	ChanCb chan func()
	// contains filtered or unexported fields
}

one Go per goroutine (goroutine not safe)

func New

func New(l int) *Go

func (*Go) Cb

func (g *Go) Cb(cb func())

func (*Go) Close

func (g *Go) Close()

func (*Go) Go

func (g *Go) Go(f func(), cb func())

func (*Go) Idle

func (g *Go) Idle() bool

func (*Go) NewLinearContext

func (g *Go) NewLinearContext() *LinearContext

type LinearContext

type LinearContext struct {
	// contains filtered or unexported fields
}
Example
package main

import (
	"fmt"
	"time"

	g "github.com/eric2918/leaf-cluster/go"
)

func main() {
	d := g.New(10)

	// parallel
	d.Go(func() {
		time.Sleep(time.Second / 2)
		fmt.Println("1")
	}, nil)
	d.Go(func() {
		fmt.Println("2")
	}, nil)

	d.Cb(<-d.ChanCb)
	d.Cb(<-d.ChanCb)

	// linear
	c := d.NewLinearContext()
	c.Go(func() {
		time.Sleep(time.Second / 2)
		fmt.Println("1")
	}, nil)
	c.Go(func() {
		fmt.Println("2")
	}, nil)

	d.Close()

}
Output:

2
1
1
2

func (*LinearContext) Go

func (c *LinearContext) Go(f func(), cb func())

type LinearGo

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

Jump to

Keyboard shortcuts

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