-
Notifications
You must be signed in to change notification settings - Fork 111
/
skeleton_block.go
53 lines (48 loc) · 1.35 KB
/
skeleton_block.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
52
53
package library
import (
"github.com/nytlabs/streamtools/st/blocks" // blocks
)
// specify those channels we're going to use to communicate with streamtools
type Skeleton struct {
blocks.Block
queryrule chan chan interface{}
inrule chan interface{}
inpoll chan interface{}
in chan interface{}
out chan interface{}
quit chan interface{}
}
// we need to build a simple factory so that streamtools can make new blocks of this kind
func NewSkeleton() blocks.BlockInterface {
return &Skeleton{}
}
// Setup is called once before running the block. We build up the channels and specify what kind of block this is.
func (b *Skeleton) Setup() {
b.Kind = "Skeleton"
b.Desc = "use this block as a starting template for creating new blocks"
b.in = b.InRoute("in")
b.inrule = b.InRoute("rule")
b.queryrule = b.QueryRoute("rule")
b.inpoll = b.InRoute("poll")
b.quit = b.Quit()
b.out = b.Broadcast()
}
// Run is the block's main loop. Here we listen on the different channels we set up.
func (b *Skeleton) Run() {
for {
select {
case ruleI := <-b.inrule:
// set a parameter of the block
_, _ = ruleI.(map[string]interface{})
case <-b.quit:
// quit the block
return
case _ = <-b.in:
// deal with inbound data
case <-b.inpoll:
// deal with a poll request
case _ = <-b.queryrule:
// deal with a query request
}
}
}