Simple WaitGroup backed by a Pub/Sub
Wanted to implement something like task groups for asynq.
Using the WaitGroup to fan-in
group := "test"
ps, _ := sync.NewPubSub(sync.NewOptions())
sink := sync.New(ps)
wg, _ := sink.WaitGroup(context.Background(), group, 512)
wg.Add(2)
wg.Wait(time.Second * 60)
Any number of children in the fan-out
group := "test"
ps, _ := sync.NewPubSub(sync.NewOptions())
sink := sync.New(ps)
sink.Done(context.TODO(), group, "one")
sink.Done(context.TODO(), group, "two")
Currently implemented is Redis, but the interface is simple enough to support any pub/sub provider. The New() function accepts the aforementioned interface, so you can pass in your own.