-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
48 lines (40 loc) · 809 Bytes
/
main.go
File metadata and controls
48 lines (40 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"context"
"fmt"
"log"
"net/http"
_ "net/http/pprof"
"time"
"github.com/devflex-pro/chanprobe"
)
func main() {
ctx := context.Background()
jobs := chanprobe.New[string]("http_debug_jobs", 16)
defer jobs.Close()
chanprobe.PublishExpvar("chanprobe", nil)
go func() {
ticker := time.NewTicker(250 * time.Millisecond)
defer ticker.Stop()
for i := 0; ; i++ {
<-ticker.C
if err := jobs.Send(ctx, fmt.Sprintf("job-%d", i)); err != nil {
return
}
}
}()
go func() {
for {
job, ok := jobs.Recv(ctx)
if !ok {
return
}
log.Println("processed", job)
time.Sleep(500 * time.Millisecond)
}
}()
log.Println("listening on http://localhost:8080/debug/vars")
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}
}