-
Notifications
You must be signed in to change notification settings - Fork 0
/
impromptu.go
51 lines (42 loc) · 900 Bytes
/
impromptu.go
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
49
50
51
package impromptu
import (
"context"
"errors"
"fmt"
"github.com/lovromazgon/impromptu/dash"
"github.com/lovromazgon/impromptu/opt"
"github.com/lovromazgon/impromptu/prom"
"golang.org/x/sync/errgroup"
)
type Impromptu struct {
prom *prom.Prom
dash *dash.Dash
}
func New(options opt.Options) (*Impromptu, error) {
p, err := prom.New(options)
if err != nil {
return nil, fmt.Errorf("error creating prom: %w", err)
}
d, err := dash.New(options)
if err != nil {
return nil, fmt.Errorf("error creating dash: %w", err)
}
return &Impromptu{
prom: p,
dash: d,
}, nil
}
func (i *Impromptu) Run(ctx context.Context) error {
group, ctx := errgroup.WithContext(ctx)
group.Go(func() error {
return i.prom.Run(ctx)
})
group.Go(func() error {
return i.dash.Run(ctx, i.prom.Out())
})
err := group.Wait()
if errors.Is(err, context.Canceled) {
return nil
}
return err
}