-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
conn_handler_example_test.go
54 lines (40 loc) · 1.14 KB
/
conn_handler_example_test.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
package neffos
import (
"fmt"
)
func ExampleEvents_On() {
events := make(Events)
events.On(OnNamespaceConnected, nil)
events.On("chat", nil)
fmt.Println(len(events)) // we can't loop them and expect the same order ofc.
// Output:
// 2
}
func ExampleNamespaces_On() {
nss := make(Namespaces)
nss.On("default", OnNamespaceConnected, nil).
On("chat", nil) // registers on "default"
nss.On("other", "chat", nil)
nss.On("other", "event", nil)
fmt.Println(len(nss))
// Output:
// 2
}
type testExampleConnHandler struct{}
func (h *testExampleConnHandler) OnConnected(*NSConn, Message) error { return nil }
func (h *testExampleConnHandler) OnChat(*NSConn, Message) error { return nil }
func (h *testExampleConnHandler) GetNamespaces() Namespaces {
nss := make(Namespaces)
nss.On("default", OnNamespaceConnected, h.OnConnected).
On("chat", h.OnChat) // registers on "default"
nss.On("other", "chat", h.OnChat)
nss.On("other2", "chat", h.OnChat)
return nss
}
var _ ConnHandler = (*testExampleConnHandler)(nil)
func ExampleConnHandler_GetNamespaces() {
h := new(testExampleConnHandler)
fmt.Println(len(h.GetNamespaces()))
// Output:
// 3
}