Add WebRTC sources for Amazon Kinesis and Wyze

This commit is contained in:
Alexey Khit
2023-07-19 23:19:05 +03:00
parent 7928f54a95
commit 3343c78699
6 changed files with 334 additions and 46 deletions
+10 -7
View File
@@ -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()
}()
}