-
Notifications
You must be signed in to change notification settings - Fork 35
/
bh.go
49 lines (39 loc) · 1.05 KB
/
bh.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
package beehive
import (
"sync"
"golang.org/x/net/context"
)
//DefaultHive is the hive used by Start() and NewApp().
var DefaultHive Hive
// Start starts the DefaultHive. This method blocks.
func Start() error {
maybeInitDefaultHive()
return DefaultHive.Start()
}
// Stop stops the DefaultHive. This method blocks.
func Stop() error {
maybeInitDefaultHive()
return DefaultHive.Stop()
}
// NewApp creates a new application on DefaultHive.
func NewApp(name string, options ...AppOption) App {
maybeInitDefaultHive()
return DefaultHive.NewApp(name, options...)
}
// Emit emits a message on DefaultHive.
func Emit(msgData interface{}) {
maybeInitDefaultHive()
DefaultHive.Emit(msgData)
}
// Sync processes a synchrounous message (req) and blocks until the response
// is recieved on DefaultHive.
func Sync(ctx context.Context, req interface{}) (res interface{}, err error) {
maybeInitDefaultHive()
return DefaultHive.Sync(ctx, req)
}
var defaultHiveInit sync.Once
func maybeInitDefaultHive() {
defaultHiveInit.Do(func() {
DefaultHive = NewHive()
})
}