-
Notifications
You must be signed in to change notification settings - Fork 4
/
receipts.go
53 lines (45 loc) · 1.06 KB
/
receipts.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
/*
* Copyright (c) 2013 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Seth Hoenig
* Allan Stockdill-Mander
* Mike Robertson
*/
package mqtt
import (
"sync"
)
// Receipt is a sort of token object that you will receive
// upon delivery of a published message.
type Receipt struct {
}
// A synchronized map for MId => chan Receipt
type receiptMap struct {
sync.RWMutex
contents map[MId]chan Receipt
}
func newReceiptMap() *receiptMap {
return &receiptMap{contents: make(map[MId]chan Receipt, 128)}
}
func (m *receiptMap) put(mid MId, c chan Receipt) {
m.Lock()
defer m.Unlock()
m.contents[mid] = c
}
func (m *receiptMap) get(mid MId) chan Receipt {
m.RLock()
defer m.RUnlock()
return m.contents[mid]
}
func (m *receiptMap) end(mid MId) {
m.Lock()
defer m.Unlock()
close(m.contents[mid])
delete(m.contents, mid)
}