• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tarantool / go-tarantool / 13930913017

18 Mar 2025 06:33PM UTC coverage: 75.939% (+0.08%) from 75.863%
13930913017

Pull #435

github

maksim.konovalov
pool: Pooler interface supports GetInfo method in TopologyEditor
Pull Request #435: pool: Pooler interface supports GetInfo method in TopologyEditor

2992 of 3940 relevant lines covered (75.94%)

9863.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.06
/watch.go
1
package tarantool
2

3
import (
4
        "context"
5
        "io"
6

7
        "github.com/tarantool/go-iproto"
8
        "github.com/vmihailenco/msgpack/v5"
9
)
10

11
// BroadcastRequest helps to send broadcast messages. See:
12
// https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_events/broadcast/
13
type BroadcastRequest struct {
14
        call *CallRequest
15
        key  string
16
}
17

18
// NewBroadcastRequest returns a new broadcast request for a specified key.
19
func NewBroadcastRequest(key string) *BroadcastRequest {
22✔
20
        req := new(BroadcastRequest)
22✔
21
        req.key = key
22✔
22
        req.call = NewCallRequest("box.broadcast").Args([]interface{}{key})
22✔
23
        return req
22✔
24
}
22✔
25

26
// Value sets the value for the broadcast request.
27
// Note: default value is nil.
28
func (req *BroadcastRequest) Value(value interface{}) *BroadcastRequest {
15✔
29
        req.call = req.call.Args([]interface{}{req.key, value})
15✔
30
        return req
15✔
31
}
15✔
32

33
// Context sets a passed context to the broadcast request.
34
func (req *BroadcastRequest) Context(ctx context.Context) *BroadcastRequest {
1✔
35
        req.call = req.call.Context(ctx)
1✔
36
        return req
1✔
37
}
1✔
38

39
// Code returns IPROTO code for the broadcast request.
40
func (req *BroadcastRequest) Type() iproto.Type {
15✔
41
        return req.call.Type()
15✔
42
}
15✔
43

44
// Body fills an msgpack.Encoder with the broadcast request body.
45
func (req *BroadcastRequest) Body(res SchemaResolver, enc *msgpack.Encoder) error {
16✔
46
        return req.call.Body(res, enc)
16✔
47
}
16✔
48

49
// Ctx returns a context of the broadcast request.
50
func (req *BroadcastRequest) Ctx() context.Context {
30✔
51
        return req.call.Ctx()
30✔
52
}
30✔
53

54
// Async returns is the broadcast request expects a response.
55
func (req *BroadcastRequest) Async() bool {
15✔
56
        return req.call.Async()
15✔
57
}
15✔
58

59
// Response creates a response for a BroadcastRequest.
60
func (req *BroadcastRequest) Response(header Header, body io.Reader) (Response, error) {
16✔
61
        return DecodeBaseResponse(header, body)
16✔
62
}
16✔
63

64
// watchRequest subscribes to the updates of a specified key defined on the
65
// server. After receiving the notification, you should send a new
66
// watchRequest to acknowledge the notification.
67
type watchRequest struct {
68
        baseRequest
69
        key string
70
        ctx context.Context
71
}
72

73
// newWatchRequest returns a new watchRequest.
74
func newWatchRequest(key string) *watchRequest {
707✔
75
        req := new(watchRequest)
707✔
76
        req.rtype = iproto.IPROTO_WATCH
707✔
77
        req.async = true
707✔
78
        req.key = key
707✔
79
        return req
707✔
80
}
707✔
81

82
// Body fills an msgpack.Encoder with the watch request body.
83
func (req *watchRequest) Body(res SchemaResolver, enc *msgpack.Encoder) error {
700✔
84
        if err := enc.EncodeMapLen(1); err != nil {
700✔
85
                return err
×
86
        }
×
87
        if err := enc.EncodeUint(uint64(iproto.IPROTO_EVENT_KEY)); err != nil {
700✔
88
                return err
×
89
        }
×
90
        return enc.EncodeString(req.key)
700✔
91
}
92

93
// Context sets a passed context to the request.
94
func (req *watchRequest) Context(ctx context.Context) *watchRequest {
388✔
95
        req.ctx = ctx
388✔
96
        return req
388✔
97
}
388✔
98

99
// unwatchRequest unregisters a watcher subscribed to the given notification
100
// key.
101
type unwatchRequest struct {
102
        baseRequest
103
        key string
104
        ctx context.Context
105
}
106

107
// newUnwatchRequest returns a new unwatchRequest.
108
func newUnwatchRequest(key string) *unwatchRequest {
8✔
109
        req := new(unwatchRequest)
8✔
110
        req.rtype = iproto.IPROTO_UNWATCH
8✔
111
        req.async = true
8✔
112
        req.key = key
8✔
113
        return req
8✔
114
}
8✔
115

116
// Body fills an msgpack.Encoder with the unwatch request body.
117
func (req *unwatchRequest) Body(res SchemaResolver, enc *msgpack.Encoder) error {
8✔
118
        if err := enc.EncodeMapLen(1); err != nil {
8✔
119
                return err
×
120
        }
×
121
        if err := enc.EncodeUint(uint64(iproto.IPROTO_EVENT_KEY)); err != nil {
8✔
122
                return err
×
123
        }
×
124
        return enc.EncodeString(req.key)
8✔
125
}
126

127
// Context sets a passed context to the request.
128
func (req *unwatchRequest) Context(ctx context.Context) *unwatchRequest {
8✔
129
        req.ctx = ctx
8✔
130
        return req
8✔
131
}
8✔
132

133
// WatchEvent is a watch notification event received from a server.
134
type WatchEvent struct {
135
        Conn  *Connection // A source connection.
136
        Key   string      // A key.
137
        Value interface{} // A value.
138
}
139

140
// Watcher is a subscription to broadcast events.
141
type Watcher interface {
142
        // Unregister unregisters the watcher.
143
        Unregister()
144
}
145

146
// WatchCallback is a callback to invoke when the key value is updated.
147
type WatchCallback func(event WatchEvent)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc