-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpriority_select.go
29 lines (25 loc) · 975 Bytes
/
priority_select.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
package priority_channels
import (
"context"
"github.com/dimag-jfrog/priority-channels/channels"
)
func Select[T any](ctx context.Context,
channelsWithPriorities []channels.ChannelWithPriority[T],
options ...func(*PriorityChannelOptions)) (msg T, channelName string, status ReceiveStatus, err error) {
pc, err := NewByHighestAlwaysFirst(context.Background(), channelsWithPriorities, options...)
if err != nil {
return getZero[T](), "", ReceiveStatusUnknown, err
}
msg, channelName, status = pc.ReceiveWithContext(ctx)
return
}
func SelectWithDefaultCase[T any](
channelsWithPriorities []channels.ChannelWithPriority[T],
options ...func(*PriorityChannelOptions)) (msg T, channelName string, status ReceiveStatus, err error) {
pc, err := NewByHighestAlwaysFirst(context.Background(), channelsWithPriorities, options...)
if err != nil {
return getZero[T](), "", ReceiveStatusUnknown, err
}
msg, channelName, status = pc.ReceiveWithDefaultCase()
return
}