-
Notifications
You must be signed in to change notification settings - Fork 1
/
crdtwrap.go
46 lines (35 loc) · 899 Bytes
/
crdtwrap.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
// crdtwrap.go
package crdt
import (
"context"
"github.com/nsip/vvmap"
)
//
// wraps the raw crdt in the CRDTData package to add relevant meta-data
//
func crdtWrap(ctx context.Context, in <-chan *vvmap.Map) (
<-chan CRDTData, // emits crdtData objects
<-chan error, // emits errors encountered to the pipeline manager
error) { // any error encountered when creating this component
out := make(chan CRDTData)
errc := make(chan error, 1)
go func() {
defer close(out)
defer close(errc)
for crdt := range in {
objectId := crdt.Keys()[0]
cd := CRDTData{
N3id: objectId,
RawData: crdt.Get(objectId).(map[string]interface{}),
CRDT: crdt,
UserId: string(crdt.ID()),
}
select {
case out <- cd: // pass the data package on to the next stage
case <-ctx.Done(): // listen for pipeline shutdown
return
}
}
}()
return out, errc, nil
}