forked from tideland/golib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
broadcaster.go
56 lines (45 loc) · 1.24 KB
/
broadcaster.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
54
55
56
// Tideland Go Library - Cell Behaviors - Broadcaster
//
// Copyright (C) 2010-2015 Frank Mueller / Oldenburg / Germany
//
// All rights reserved. Use of this source code is governed
// by the new BSD license.
package behaviors
//--------------------
// IMPORTS
//--------------------
import (
"github.com/tideland/golib/cells"
)
//--------------------
// BROADCASTER BEHAVIOR
//--------------------
// broadcasterBehavior is a simple repeater.
type broadcasterBehavior struct {
ctx cells.Context
}
// NewBroadcasterBehavior creates a broadcasting behavior that just emits every
// received event. It's intended to work as an entry point for events, which
// shall be immediately processed by several subscribers.
func NewBroadcasterBehavior() cells.Behavior {
return &broadcasterBehavior{}
}
// Init the behavior.
func (b *broadcasterBehavior) Init(ctx cells.Context) error {
b.ctx = ctx
return nil
}
// Terminate the behavior.
func (b *broadcasterBehavior) Terminate() error {
return nil
}
// ProcessEvent emits the event to all subscribers.
func (b *broadcasterBehavior) ProcessEvent(event cells.Event) error {
b.ctx.Emit(event)
return nil
}
// Recover from an error.
func (b *broadcasterBehavior) Recover(err interface{}) error {
return nil
}
// EOF