| // Copyright 2015 The Vanadium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| // A Barrier is a simple incremental barrier that runs a done closure after |
| // all closures returned by Add() have been invoked. The done closure will |
| // run only once and run in a separate goroutine. |
| // Add increments the barrier. Each closure returned by Add() should eventually |
| // be run once, otherwise 'done' will never be run. It returns nil if the done |
| // closure has been already called. |
| func (b *Barrier) Add() func() { |
| func (b *Barrier) run() { |
| func NewBarrier(done func()) *Barrier { |
| return &Barrier{done: done} |