-
Notifications
You must be signed in to change notification settings - Fork 111
/
fromPost.go
43 lines (38 loc) · 1.03 KB
/
fromPost.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
package library
import (
"github.com/nytlabs/streamtools/st/blocks" // blocks
)
// specify those channels we're going to use to communicate with streamtools
type FromPost struct {
blocks.Block
queryrule chan chan interface{}
inrule 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 NewFromPost() blocks.BlockInterface {
return &FromPost{}
}
// Setup is called once before running the block. We build up the channels and specify what kind of block this is.
func (b *FromPost) Setup() {
b.Kind = "FromPost"
b.Desc = "emits any message that is POSTed to its IN route"
b.in = b.InRoute("in")
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 *FromPost) Run() {
for {
select {
case <-b.quit:
// quit the block
return
case msg := <-b.in:
// deal with inbound data
b.out <- msg
}
}
}