golanggohlsrtmpwebrtcmedia-serverobs-studiortcprtmp-proxyrtmp-serverrtprtsprtsp-proxyrtsp-relayrtsp-serversrtstreamingwebrtc-proxy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
832 B
52 lines
832 B
package hls |
|
|
|
import ( |
|
"context" |
|
"sync" |
|
) |
|
|
|
type clientRoutinePoolRunnable interface { |
|
run(context.Context) error |
|
} |
|
|
|
type clientRoutinePool struct { |
|
ctx context.Context |
|
ctxCancel func() |
|
wg sync.WaitGroup |
|
|
|
err chan error |
|
} |
|
|
|
func newClientRoutinePool() *clientRoutinePool { |
|
ctx, ctxCancel := context.WithCancel(context.Background()) |
|
|
|
return &clientRoutinePool{ |
|
ctx: ctx, |
|
ctxCancel: ctxCancel, |
|
err: make(chan error), |
|
} |
|
} |
|
|
|
func (rp *clientRoutinePool) close() { |
|
rp.ctxCancel() |
|
rp.wg.Wait() |
|
} |
|
|
|
func (rp *clientRoutinePool) errorChan() chan error { |
|
return rp.err |
|
} |
|
|
|
func (rp *clientRoutinePool) add(r clientRoutinePoolRunnable) { |
|
rp.wg.Add(1) |
|
go func() { |
|
defer rp.wg.Done() |
|
|
|
err := r.run(rp.ctx) |
|
if err != nil { |
|
select { |
|
case rp.err <- err: |
|
case <-rp.ctx.Done(): |
|
} |
|
} |
|
}() |
|
}
|
|
|