-
Notifications
You must be signed in to change notification settings - Fork 87
/
session.go
56 lines (45 loc) · 936 Bytes
/
session.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
package turnpike
import (
"fmt"
)
// Session represents an active WAMP session
type Session struct {
Peer
Id ID
Details map[string]interface{}
kill chan URI
}
func (s Session) String() string {
return fmt.Sprintf("%d", s.Id)
}
// localPipe creates two linked sessions. Messages sent to one will
// appear in the Receive of the other. This is useful for implementing
// client sessions
func localPipe() (*localPeer, *localPeer) {
aToB := make(chan Message, 10)
bToA := make(chan Message, 10)
a := &localPeer{
incoming: bToA,
outgoing: aToB,
}
b := &localPeer{
incoming: aToB,
outgoing: bToA,
}
return a, b
}
type localPeer struct {
outgoing chan<- Message
incoming <-chan Message
}
func (s *localPeer) Receive() <-chan Message {
return s.incoming
}
func (s *localPeer) Send(msg Message) error {
s.outgoing <- msg
return nil
}
func (s *localPeer) Close() error {
close(s.outgoing)
return nil
}