multithreading

package
v0.0.0-...-3aa5266 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StopMode

type StopMode uint8

StopMode represents the behavior of the threadTracker once it has been stopped

const (
	StopModeError StopMode = iota
	StopModeNoop
)

types of StopMode

type ThreadTracker

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

ThreadTracker allows you to easily manage goroutines

func MakeThreadTracker

func MakeThreadTracker() *ThreadTracker

MakeThreadTracker is a factory method for ThreadTracker

func (*ThreadTracker) NumActiveThreads

func (t *ThreadTracker) NumActiveThreads() uint64

NumActiveThreads fetches the number of active threads managed by this threadTracker

func (*ThreadTracker) Stop

func (t *ThreadTracker) Stop(stopMode StopMode)

Stop prevents this threadTracker from accepting any more threads

func (*ThreadTracker) TriggerGoroutine

func (t *ThreadTracker) TriggerGoroutine(fn func(inputs []interface{}), inputs []interface{}) error

TriggerGoroutine initiates a new goroutine while tracking it typical usage 1:

threadTracker.TriggerGoroutine(func(inputs []interface{}) {
    fmt.Printf("Hello %s\n", "World")
})

typical usage 2:

threadTracker.TriggerGoroutine(func(inputs []interface{}) {
    fmt.Printf("Hello %s\n", inputs[0])
}, "World")

func (*ThreadTracker) TriggerGoroutineWithDefers

func (t *ThreadTracker) TriggerGoroutineWithDefers(deferredFns []func(), fn func(inputs []interface{}), inputs []interface{}) error

TriggerGoroutineWithDefers initiates a new goroutine while tracking it typical usage:

    threadTracker.TriggerGoroutineWithDefers([]func(){
	       func() { fmt.Printf("this should appear third\n") },
	       func() { fmt.Printf("this should appear second\n") },
    }, func(inputs []interface{}) {
        fmt.Printf("Hello %s -- this should appear first\n", "World")
    })

func (*ThreadTracker) Wait

func (t *ThreadTracker) Wait()

Wait blocks until all goroutines finish

Jump to

Keyboard shortcuts

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