bakalover / tate

Structured concurrency

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tate - structured concurrency

Never write go statement again!

  • Manual gorroutine handle:
h := tate.Go(func(){})
h.Join() // Ok
h.Join() // panic! -> Double join
  • Fixed Scope:
tate.FixScope(func(s *Scope){
    s.Go(func(){})
    s.Go(func(){})
    s.Go(func(){})
}) // Synchronous wait of all goroutines
  • Dynamic Scope:
j := tate.DynScope(func(s *Scope){
    s.Go(func(){})
    s.Go(func(){})
    s.Go(func(){})
}) 

j.Join() // Only at that point all goroutines are done
j.Join() // panic! -> Double join
  • Repeater
rp := tate.NewRepeater()
// Repeats in infinite cycle each routine
rp.Go(func(){})
rp.Go(func(){})
// Instantly cancels all cycles and joins goroutines
rp.CancelJoin() 

// We can do it again and again
rp.Go(func(){})
rp.Go(func(){})
rp.CancelJoin() 

Todo

  • Tree Design
  • Inject Cancellation
  • Maybe some functional style

Reference

About

Structured concurrency


Languages

Language:Go 100.0%