mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-12 00:27:35 +02:00
fileutil: update watcher to use fsnotify and polling (#3663)
* fileutil: update watcher to use fsnotify and polling * raise timeout * maybe fix
This commit is contained in:
parent
daed2d260c
commit
d147846e64
9 changed files with 315 additions and 34 deletions
46
internal/chanutil/merge.go
Normal file
46
internal/chanutil/merge.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package chanutil
|
||||
|
||||
// Merge merges multiple channels together.
|
||||
func Merge[T any](ins ...<-chan T) <-chan T {
|
||||
switch len(ins) {
|
||||
case 0:
|
||||
return nil
|
||||
case 1:
|
||||
return ins[0]
|
||||
case 2:
|
||||
default:
|
||||
return Merge(
|
||||
Merge(ins[:len(ins)/2]...),
|
||||
Merge(ins[len(ins)/2:]...),
|
||||
)
|
||||
}
|
||||
|
||||
in1, in2 := ins[0], ins[1]
|
||||
out := make(chan T)
|
||||
go func() {
|
||||
for {
|
||||
if in1 == nil && in2 == nil {
|
||||
close(out)
|
||||
return
|
||||
}
|
||||
|
||||
select {
|
||||
case item, ok := <-in1:
|
||||
if !ok {
|
||||
in1 = nil
|
||||
continue
|
||||
}
|
||||
|
||||
out <- item
|
||||
case item, ok := <-in2:
|
||||
if !ok {
|
||||
in2 = nil
|
||||
continue
|
||||
}
|
||||
|
||||
out <- item
|
||||
}
|
||||
}
|
||||
}()
|
||||
return out
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue