-
Notifications
You must be signed in to change notification settings - Fork 8
/
mounted-stream.go
51 lines (43 loc) · 1.4 KB
/
mounted-stream.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 pubsub_controller
import (
"context"
"github.com/aperturerobotics/bifrost/link"
"github.com/aperturerobotics/controllerbus/directive"
)
// handleMountedStreamResolver resolves HandleMountedStream.
type handleMountedStreamResolver struct {
c *Controller
}
func newHandleMountedStreamResolver(c *Controller) *handleMountedStreamResolver {
return &handleMountedStreamResolver{c: c}
}
// Resolve resolves the values, emitting them to the handler.
// The resolver may be canceled and restarted multiple times.
// Any fatal error resolving the value is returned.
// The resolver will not be retried after returning an error.
// Values will be maintained from the previous call.
func (r *handleMountedStreamResolver) Resolve(
ctx context.Context,
handler directive.ResolverHandler,
) error {
ps, err := r.c.GetPubSub(ctx)
if err != nil {
return err
}
var val link.MountedStreamHandler = newStreamHandler(r.c, ps)
_, _ = handler.AddValue(val)
return nil
}
// handleMountedStream handles the HandleMountedStream directive.
func (c *Controller) handleMountedStream(
ctx context.Context,
di directive.Instance,
dir link.HandleMountedStream,
) ([]directive.Resolver, error) {
if dir.HandleMountedStreamProtocolID() != c.protocolID {
return nil, nil
}
return directive.Resolvers(newHandleMountedStreamResolver(c)), nil
}
// _ is a type assertion
var _ directive.Resolver = ((*handleMountedStreamResolver)(nil))