-
Notifications
You must be signed in to change notification settings - Fork 31
/
harness.go
41 lines (30 loc) · 928 Bytes
/
harness.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
package harness
import (
"context"
"github.com/digital-dream-labs/vector-cloud/internal/clad/cloud"
"github.com/digital-dream-labs/vector-cloud/internal/cloudproc"
"github.com/digital-dream-labs/vector-cloud/internal/voice"
)
type Harness interface {
voice.MsgIO
ReadMessage() (*cloud.Message, error)
}
type memHarness struct {
voice.MsgIO
intent chan *cloud.Message
}
func (h *memHarness) ReadMessage() (*cloud.Message, error) {
return <-h.intent, nil
}
func CreateMemProcess(ctx context.Context, options ...cloudproc.Option) (Harness, error) {
intentResult := make(chan *cloud.Message)
io, receiver := voice.NewMemPipe()
process := &voice.Process{}
process.AddReceiver(receiver)
process.AddIntentWriter(&voice.ChanMsgSender{Ch: intentResult})
options = append(options, cloudproc.WithVoice(process))
go cloudproc.Run(ctx, options...)
return &memHarness{
MsgIO: io,
intent: intentResult}, nil
}