Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
/ parallel Public archive

Go library for structured parallelism

License

Notifications You must be signed in to change notification settings

ridge/parallel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go library for structured concurrency

go.dev reference

This repository is archived. See https://github.com/dottedmag/parallel for the current version.

Structured concurrency helps reasoning about the behaviour of parallel programs. parallel implements structured concurrency for Go.

func subtask(ctx context.Context) error {
    // to be run in parallel
}

type subtaskWithData struct { /* ... * / }

func (swd *subtaskWithData) Run(ctx context.Context) error {
    // to be run in parallel
}

err := parallel.Run(ctx, func(ctx context.Context, spawn parallel.SpawnFn) error {
    swd := &subtaskWithData{}

    // do some synchronous initialization here

    spawn("subtask", parallel.Fail, subtask)
    spawn("subtaskWithData", parallel.Fail, swd.Run)
    return nil
})

Runs initializaiton within parallel.Run(), and then waits until context is canceled, or one of spawned tasks finishes. Panics in goroutines are captured.

See the documentation for additional features:

  • subprocess groups without inversion of control
  • tasks that may exit and keep the group running
  • tasks that may exit and cause the group to stop gracefully

Legal

Copyright Tectonic Labs Ltd.

Licensed under Apache 2.0 license.

Authors:

About

Go library for structured parallelism

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages