This repository has been archived by the owner on Jan 23, 2022. It is now read-only.
/
notification.go
53 lines (43 loc) · 1.66 KB
/
notification.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
package rinq
import (
"context"
"github.com/rinq/rinq-go/src/rinq/constraint"
"github.com/rinq/rinq-go/src/rinq/ident"
)
// Notification holds information about an inter-session notification.
type Notification struct {
// ID uniquely identifies the notification.
ID ident.MessageID
// Source refers to the session that sent the notification.
Source Revision
// Namespace is the notification namespace. Namespaces are used to route
// notifications to only those sessions that intend to handle them.
Namespace string
// Type is an application-defined notification type.
Type string
// Payload contains optional application-defined information. The handler
// that accepts the notifiation is responsible for closing the payload,
// however there is no requirement that the payload be closed during the
// execution of the handler.
Payload *Payload
// IsMulticast is true if the notification was (potentially) sent to more
// than one session.
IsMulticast bool
// For multicast notifications, Constraint contains the attributes used as
// criteria for selecting which sessions receive the notification. The
// constraint is nil if IsMulticast is false.
Constraint constraint.Constraint
}
// NotificationHandler is a callback-function invoked when an inter-session
// notification is received.
//
// Notifications can only be received for namespaces that a session is listening
// to. See Session.Listen() to start listening.
//
// The handler is responsible for closing n.Payload, however there is no
// requirement that the payload be closed during the execution of the handler.
type NotificationHandler func(
ctx context.Context,
target Session,
n Notification,
)