sync
This commit is contained in:
248
cover.html
Normal file
248
cover.html
Normal file
@@ -0,0 +1,248 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>bus: Go Coverage Report</title>
|
||||
<style>
|
||||
body {
|
||||
background: black;
|
||||
color: rgb(80, 80, 80);
|
||||
}
|
||||
body, pre, #legend span {
|
||||
font-family: Menlo, monospace;
|
||||
font-weight: bold;
|
||||
}
|
||||
#topbar {
|
||||
background: black;
|
||||
position: fixed;
|
||||
top: 0; left: 0; right: 0;
|
||||
height: 42px;
|
||||
border-bottom: 1px solid rgb(80, 80, 80);
|
||||
}
|
||||
#content {
|
||||
margin-top: 50px;
|
||||
}
|
||||
#nav, #legend {
|
||||
float: left;
|
||||
margin-left: 10px;
|
||||
}
|
||||
#legend {
|
||||
margin-top: 12px;
|
||||
}
|
||||
#nav {
|
||||
margin-top: 10px;
|
||||
}
|
||||
#legend span {
|
||||
margin: 0 5px;
|
||||
}
|
||||
.cov0 { color: rgb(192, 0, 0) }
|
||||
.cov1 { color: rgb(128, 128, 128) }
|
||||
.cov2 { color: rgb(116, 140, 131) }
|
||||
.cov3 { color: rgb(104, 152, 134) }
|
||||
.cov4 { color: rgb(92, 164, 137) }
|
||||
.cov5 { color: rgb(80, 176, 140) }
|
||||
.cov6 { color: rgb(68, 188, 143) }
|
||||
.cov7 { color: rgb(56, 200, 146) }
|
||||
.cov8 { color: rgb(44, 212, 149) }
|
||||
.cov9 { color: rgb(32, 224, 152) }
|
||||
.cov10 { color: rgb(20, 236, 155) }
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="topbar">
|
||||
<div id="nav">
|
||||
<select id="files">
|
||||
|
||||
<option value="file0">github.com/gopatchy/bus/bus.go (96.2%)</option>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
<div id="legend">
|
||||
<span>not tracked</span>
|
||||
|
||||
<span class="cov0">no coverage</span>
|
||||
<span class="cov1">low coverage</span>
|
||||
<span class="cov2">*</span>
|
||||
<span class="cov3">*</span>
|
||||
<span class="cov4">*</span>
|
||||
<span class="cov5">*</span>
|
||||
<span class="cov6">*</span>
|
||||
<span class="cov7">*</span>
|
||||
<span class="cov8">*</span>
|
||||
<span class="cov9">*</span>
|
||||
<span class="cov10">high coverage</span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div id="content">
|
||||
|
||||
<pre class="file" id="file0" style="display: none">package bus
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"github.com/gopatchy/metadata"
|
||||
)
|
||||
|
||||
type Bus struct {
|
||||
mu sync.Mutex
|
||||
keyViews map[string]map[uintptr]chan<- any
|
||||
typeViews map[string]map[uintptr]chan<- any
|
||||
}
|
||||
|
||||
func NewBus() *Bus <span class="cov2" title="2">{
|
||||
return &Bus{
|
||||
keyViews: map[string]map[uintptr]chan<- any{},
|
||||
typeViews: map[string]map[uintptr]chan<- any{},
|
||||
}
|
||||
}</span>
|
||||
|
||||
func (b *Bus) Announce(t string, obj any) <span class="cov5" title="5">{
|
||||
key := getObjKey(t, obj)
|
||||
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
|
||||
announce(obj, b.keyViews[key])
|
||||
announce(obj, b.typeViews[t])
|
||||
}</span>
|
||||
|
||||
func (b *Bus) Delete(t string, id string) <span class="cov1" title="1">{
|
||||
key := getKey(t, id)
|
||||
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
|
||||
for _, c := range b.keyViews[key] </span><span class="cov1" title="1">{
|
||||
close(c)
|
||||
}</span>
|
||||
|
||||
<span class="cov1" title="1">delete(b.keyViews, key)
|
||||
|
||||
announce(id, b.typeViews[t])</span>
|
||||
}
|
||||
|
||||
func (b *Bus) SubscribeKey(t, id string, initial any) <-chan any <span class="cov5" title="5">{
|
||||
key := getKey(t, id)
|
||||
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
|
||||
ret := make(chan any, 100)
|
||||
|
||||
ret <- initial
|
||||
|
||||
if _, has := b.keyViews[key]; !has </span><span class="cov4" title="4">{
|
||||
b.keyViews[key] = map[uintptr]chan<- any{}
|
||||
}</span>
|
||||
|
||||
<span class="cov5" title="5">b.keyViews[key][chanID(ret)] = ret
|
||||
|
||||
return ret</span>
|
||||
}
|
||||
|
||||
func (b *Bus) SubscribeType(t string, initial any) <-chan any <span class="cov4" title="3">{
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
|
||||
ret := make(chan any, 100)
|
||||
|
||||
ret <- initial
|
||||
|
||||
if _, has := b.typeViews[t]; !has </span><span class="cov4" title="3">{
|
||||
b.typeViews[t] = map[uintptr]chan<- any{}
|
||||
}</span>
|
||||
|
||||
<span class="cov4" title="3">b.typeViews[t][chanID(ret)] = ret
|
||||
|
||||
return ret</span>
|
||||
}
|
||||
|
||||
func (b *Bus) UnsubscribeKey(t, id string, c <-chan any) <span class="cov5" title="5">{
|
||||
key := getKey(t, id)
|
||||
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
|
||||
if cw, has := b.keyViews[key][chanID(c)]; has </span><span class="cov4" title="4">{
|
||||
close(cw)
|
||||
delete(b.keyViews[key], chanID(c))
|
||||
}</span>
|
||||
|
||||
<span class="cov5" title="5">if len(b.keyViews[key]) == 0 </span><span class="cov4" title="4">{
|
||||
delete(b.keyViews, key)
|
||||
}</span>
|
||||
}
|
||||
|
||||
func (b *Bus) UnsubscribeType(t string, c <-chan any) <span class="cov4" title="3">{
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
|
||||
if cw, has := b.typeViews[t][chanID(c)]; has </span><span class="cov4" title="3">{
|
||||
close(cw)
|
||||
delete(b.typeViews[t], chanID(c))
|
||||
}</span>
|
||||
|
||||
<span class="cov4" title="3">if len(b.typeViews[t]) == 0 </span><span class="cov4" title="3">{
|
||||
delete(b.typeViews, t)
|
||||
}</span>
|
||||
}
|
||||
|
||||
func getObjKey(t string, obj any) string <span class="cov5" title="5">{
|
||||
return getKey(t, metadata.GetMetadata(obj).ID)
|
||||
}</span>
|
||||
|
||||
func getKey(t string, id string) string <span class="cov8" title="16">{
|
||||
return fmt.Sprintf("%s:%s", t, id)
|
||||
}</span>
|
||||
|
||||
func announce(obj any, chans map[uintptr]chan<- any) <span class="cov7" title="11">{
|
||||
for id, c := range chans </span><span class="cov7" title="10">{
|
||||
select </span>{
|
||||
case c <- obj:<span class="cov7" title="10"></span>
|
||||
default:<span class="cov0" title="0">
|
||||
close(c)
|
||||
delete(chans, id)</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func chanID(c <-chan any) uintptr <span class="cov10" title="23">{
|
||||
return reflect.ValueOf(c).Pointer()
|
||||
}</span>
|
||||
</pre>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
(function() {
|
||||
var files = document.getElementById('files');
|
||||
var visible;
|
||||
files.addEventListener('change', onChange, false);
|
||||
function select(part) {
|
||||
if (visible)
|
||||
visible.style.display = 'none';
|
||||
visible = document.getElementById(part);
|
||||
if (!visible)
|
||||
return;
|
||||
files.value = part;
|
||||
visible.style.display = 'block';
|
||||
location.hash = part;
|
||||
}
|
||||
function onChange() {
|
||||
select(files.value);
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
if (location.hash != "") {
|
||||
select(location.hash.substr(1));
|
||||
}
|
||||
if (!visible) {
|
||||
select("file0");
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</html>
|
||||
27
cover.out
Normal file
27
cover.out
Normal file
@@ -0,0 +1,27 @@
|
||||
mode: atomic
|
||||
github.com/gopatchy/bus/bus.go:17.20,22.2 1 2
|
||||
github.com/gopatchy/bus/bus.go:24.43,32.2 5 5
|
||||
github.com/gopatchy/bus/bus.go:34.43,40.36 4 1
|
||||
github.com/gopatchy/bus/bus.go:40.36,42.3 1 1
|
||||
github.com/gopatchy/bus/bus.go:44.2,46.30 2 1
|
||||
github.com/gopatchy/bus/bus.go:49.66,59.37 6 5
|
||||
github.com/gopatchy/bus/bus.go:59.37,61.3 1 4
|
||||
github.com/gopatchy/bus/bus.go:63.2,65.12 2 5
|
||||
github.com/gopatchy/bus/bus.go:68.63,76.36 5 3
|
||||
github.com/gopatchy/bus/bus.go:76.36,78.3 1 3
|
||||
github.com/gopatchy/bus/bus.go:80.2,82.12 2 3
|
||||
github.com/gopatchy/bus/bus.go:85.58,91.48 4 5
|
||||
github.com/gopatchy/bus/bus.go:91.48,94.3 2 4
|
||||
github.com/gopatchy/bus/bus.go:96.2,96.31 1 5
|
||||
github.com/gopatchy/bus/bus.go:96.31,98.3 1 4
|
||||
github.com/gopatchy/bus/bus.go:101.55,105.47 3 3
|
||||
github.com/gopatchy/bus/bus.go:105.47,108.3 2 3
|
||||
github.com/gopatchy/bus/bus.go:110.2,110.30 1 3
|
||||
github.com/gopatchy/bus/bus.go:110.30,112.3 1 3
|
||||
github.com/gopatchy/bus/bus.go:115.42,117.2 1 5
|
||||
github.com/gopatchy/bus/bus.go:119.41,121.2 1 16
|
||||
github.com/gopatchy/bus/bus.go:123.54,124.27 1 11
|
||||
github.com/gopatchy/bus/bus.go:124.27,125.10 1 10
|
||||
github.com/gopatchy/bus/bus.go:126.17,126.17 0 10
|
||||
github.com/gopatchy/bus/bus.go:127.11,129.21 2 0
|
||||
github.com/gopatchy/bus/bus.go:134.35,136.2 1 23
|
||||
Reference in New Issue
Block a user