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

hyperledger / fabric-x-committer / 26936915281

04 Jun 2026 07:15AM UTC coverage: 91.739% (+0.2%) from 91.501%
26936915281

Pull #620

github

liran-funaro
[notify] Introduce StreamAllTransactions stream

Signed-off-by: Liran Funaro <liran.funaro@gmail.com>
Pull Request #620: [notify] Introduce StreamAllTransactions stream

47 of 204 new or added lines in 6 files covered. (23.04%)

837 existing lines in 48 files now uncovered.

10406 of 11343 relevant lines covered (91.74%)

82884.38 hits per line

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

100.0
/utils/sync_map.go
1
/*
2
Copyright IBM Corp. All Rights Reserved.
3

4
SPDX-License-Identifier: Apache-2.0
5
*/
6

7
package utils
8

9
import (
10
        "iter"
11
        "sync"
12
)
13

14
// SyncMap is a wrapper for sync.Map.
15
// It enhances readability by explicitly specifying the key and value types at compile time.
16
// This also minimizes boilerplate code needed for type casting.
17
type SyncMap[K, V any] struct {
18
        m sync.Map
19
}
20

21
// Store mirrors sync.Map's method.
22
// See [sync.Map] for detailed documentation.
23
func (m *SyncMap[K, V]) Store(key K, value V) {
43,184✔
24
        m.m.Store(key, value)
43,184✔
25
}
43,184✔
26

27
// Load mirrors sync.Map's method.
28
// See [sync.Map] for detailed documentation.
29
func (m *SyncMap[K, V]) Load(key K) (value V, ok bool) {
196,498✔
30
        return makeReturn[V](m.m.Load(key))
196,498✔
31
}
196,498✔
32

33
// Swap mirrors sync.Map's method.
34
// See [sync.Map] for detailed documentation.
UNCOV
35
func (m *SyncMap[K, V]) Swap(key K, value V) (previous V, loaded bool) {
1✔
UNCOV
36
        return makeReturn[V](m.m.Swap(key, value))
1✔
UNCOV
37
}
1✔
38

39
// LoadOrStore mirrors sync.Map's method.
40
// See [sync.Map] for detailed documentation.
41
func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool) {
103,864✔
42
        return makeReturn[V](m.m.LoadOrStore(key, value))
103,864✔
43
}
103,864✔
44

45
// LoadAndDelete mirrors sync.Map's method.
46
// See [sync.Map] for detailed documentation.
47
func (m *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool) {
41,977✔
48
        return makeReturn[V](m.m.LoadAndDelete(key))
41,977✔
49
}
41,977✔
50

51
// Delete mirrors sync.Map's method.
52
// See [sync.Map] for detailed documentation.
53
func (m *SyncMap[K, V]) Delete(key K) {
96,412✔
54
        m.m.Delete(key)
96,412✔
55
}
96,412✔
56

57
// CompareAndSwap mirrors sync.Map's method.
58
// See [sync.Map] for detailed documentation.
59
func (m *SyncMap[K, V]) CompareAndSwap(key K, oldVal, newVal V) (swapped bool) {
21✔
60
        return m.m.CompareAndSwap(key, oldVal, newVal)
21✔
61
}
21✔
62

63
// CompareAndDelete mirrors sync.Map's method.
64
// See [sync.Map] for detailed documentation.
65
func (m *SyncMap[K, V]) CompareAndDelete(key K, value V) (deleted bool) {
35✔
66
        return m.m.CompareAndDelete(key, value)
35✔
67
}
35✔
68

69
// Range mirrors sync.Map's method.
70
// See [sync.Map] for detailed documentation.
71
func (m *SyncMap[K, V]) Range(f func(key K, value V) bool) {
41,811✔
72
        m.m.Range(func(k, v any) bool {
42,243✔
73
                nonNilK, _ := k.(K) //nolint:revive // all keys are of type K.
432✔
74
                nonNilV, _ := v.(V) //nolint:revive // all values are of type V.
432✔
75
                return f(nonNilK, nonNilV)
432✔
76
        })
432✔
77
}
78

79
// Clear mirrors sync.Map's method.
80
// See [sync.Map] for detailed documentation.
81
func (m *SyncMap[K, V]) Clear() {
216✔
82
        m.m.Clear()
216✔
83
}
216✔
84

85
// IterItems allows iterating over the items' key value pair.
86
// Example:
87
//
88
//        for k, v := range m.IterItems() {
89
//            fmt.Printf("%v: %v\n", k, v)
90
//        }
UNCOV
91
func (m *SyncMap[K, V]) IterItems() iter.Seq2[K, V] {
1✔
UNCOV
92
        return func(yield func(K, V) bool) {
2✔
UNCOV
93
                m.Range(yield)
1✔
UNCOV
94
        }
1✔
95
}
96

97
// IterKeys allows iterating over the items' keys.
98
// Example:
99
//
100
//        for k := range m.IterKeys() {
101
//            fmt.Printf("%v\n", k)
102
//        }
103
func (m *SyncMap[K, V]) IterKeys() iter.Seq[K] {
41,723✔
104
        return func(yield func(K) bool) {
83,446✔
105
                m.Range(func(key K, _ V) bool {
41,836✔
106
                        return yield(key)
113✔
107
                })
113✔
108
        }
109
}
110

111
// IterValues allows iterating over the items' values.
112
// Example:
113
//
114
//        for v := range m.IterValues() {
115
//            fmt.Printf("%v\n", v)
116
//        }
117
func (m *SyncMap[K, V]) IterValues() iter.Seq[V] {
86✔
118
        return func(yield func(V) bool) {
172✔
119
                m.Range(func(_ K, value V) bool {
399✔
120
                        return yield(value)
313✔
121
                })
313✔
122
        }
123
}
124

125
// Count counts the number of items in the map.
126
// It iterates over the map, so it is best to avoid it in production.
127
func (m *SyncMap[K, V]) Count() int {
133✔
128
        count := 0
133✔
129
        m.m.Range(func(_, _ any) bool {
216✔
130
                count++
83✔
131
                return true
83✔
132
        })
83✔
133
        return count
133✔
134
}
135

136
func makeReturn[T any](v any, retOK bool) (value T, ok bool) {
342,336✔
137
        if v != nil {
682,548✔
138
                value = v.(T) //nolint:errcheck,revive,forcetypeassert // all values are of type T.
340,212✔
139
        }
340,212✔
140
        return value, retOK
342,336✔
141
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc