Add WebRTC sources for Amazon Kinesis and Wyze
This commit is contained in:
+10
-7
@@ -12,6 +12,7 @@ type Waiter struct {
|
||||
sync.WaitGroup
|
||||
mu sync.Mutex
|
||||
state int // state < 0 means finish
|
||||
err error
|
||||
}
|
||||
|
||||
func (w *Waiter) Add(delta int) {
|
||||
@@ -23,7 +24,7 @@ func (w *Waiter) Add(delta int) {
|
||||
w.mu.Unlock()
|
||||
}
|
||||
|
||||
func (w *Waiter) Wait() {
|
||||
func (w *Waiter) Wait() error {
|
||||
w.mu.Lock()
|
||||
// first wait auto start waiter
|
||||
if w.state == 0 {
|
||||
@@ -33,9 +34,11 @@ func (w *Waiter) Wait() {
|
||||
w.mu.Unlock()
|
||||
|
||||
w.WaitGroup.Wait()
|
||||
|
||||
return w.err
|
||||
}
|
||||
|
||||
func (w *Waiter) Done() {
|
||||
func (w *Waiter) Done(err error) {
|
||||
w.mu.Lock()
|
||||
|
||||
// safe run Done only when have tasks
|
||||
@@ -47,21 +50,21 @@ func (w *Waiter) Done() {
|
||||
// block waiter for any operations after last done
|
||||
if w.state == 0 {
|
||||
w.state = -1
|
||||
w.err = err
|
||||
}
|
||||
|
||||
w.mu.Unlock()
|
||||
}
|
||||
|
||||
func (w *Waiter) WaitChan() <-chan struct{} {
|
||||
var ch chan struct{}
|
||||
func (w *Waiter) WaitChan() <-chan error {
|
||||
var ch chan error
|
||||
|
||||
w.mu.Lock()
|
||||
|
||||
if w.state >= 0 {
|
||||
ch = make(chan struct{})
|
||||
ch = make(chan error)
|
||||
go func() {
|
||||
w.Wait()
|
||||
ch <- struct{}{}
|
||||
ch <- w.Wait()
|
||||
}()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user