Skip to content

Simple fork and join of goroutines- easy to use; no fuss.

License

Notifications You must be signed in to change notification settings

rickb777/process

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

process - goroutines as contained processes

GoDoc Go Report Card

Simple fork and join of goroutines - easy to use; no fuss.

Puts the 'P' of CSP back into Go.

All it does is handle the join when a group of goroutines terminate. Internally, a sync.WaitGroup is administered for you. There's not much to it but it makes your job easier.

Installation

go get -u github.com/rickb777/process

How To

Just create a new group then tell some functions to Go:

	processes := process.NewGroup()
	processes.Go(func() {
		...  some work, just a normal goroutine function
	})
	processes.Go(func() {
		...  some other work
	})
	processes.Join()

The Join() method does not terminate until all the sub-processes have terminated. In other words, the code that follows has to wait until then.

The second way to use process groups is to start a pool of several identical goroutines using GoN:

	processes := process.NewGroup()
	processes.GoN(3, func() {
		...  some work, just a normal goroutine function
	})
	processes.Join()

You can of course mix Go and GoN in the same process group:

	processes := process.NewGroup()
	processes.GoN(3, func() {
		...  some work, just a normal goroutine function
	})
	processes.Go(func() {
		...  some other work
	})
	processes.Join()

GoN1 is a variant of GoN that provides the index counter as a parameter, counting up from 1:

	processes := process.NewGroup()
	processes.GoN1(3, func(i int) {
		...  some work, just a normal goroutine function
	})
	processes.Join()

Hierarchies

A process group contains processes. These processes can also be process groups, or they can contain process groups. As long as the Join calls are positioned so that each group terminates tidily, the nesting should just work (TM).

Licence

MIT

About

Simple fork and join of goroutines- easy to use; no fuss.

Resources

License

Stars

Watchers

Forks

Packages

No packages published