-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.go
90 lines (77 loc) · 2.9 KB
/
utils.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package actorkit
import (
"sync"
"time"
)
//****************************************************************
// Formatter functions
//****************************************************************
// FormatAddrChild returns the official address format for which
// the actorkit package uses for representing the parent + child address
// value.
func FormatAddrChild(parentAddr string, childID string) string {
return parentAddr + "/" + childID
}
// FormatNamespace returns the official namespace format for which
// the actorkit package uses for representing the protocol+namespace
// value for a actor or it's addresses.
func FormatNamespace(protocol string, namespace string) string {
return protocol + "@" + namespace
}
// FormatService returns the official ProtocolAddr format for which
// the actorkit package uses for representing the protocol+namespace+service
// value for a actor or it's addresses.
func FormatService(protocol string, namespace string, service string) string {
return protocol + "@" + namespace + "/" + service
}
// FormatAddr returns the official address format for which
// the actorkit package uses for representing the protocol+namespace+uuid
// value for a actor or it's addresses.
func FormatAddr(protocol string, namespace string, id string) string {
return protocol + "@" + namespace + "/" + id
}
// FormatAddrService returns the official address format for which the
// actorkit package uses for formatting a actor's service address format.
func FormatAddrService(protocol string, namespace string, id string, service string) string {
return protocol + "@" + namespace + "/" + id + "/" + service
}
// formatAddr2 returns the second official address format for which
// the actorkit package uses for representing the formatted_addr+uuid
// value for a actor.
func formatAddr2(addr string, id string) string {
return addr + "/" + id
}
// formatAddrService2 returns the official address format for which the
// actorkit package uses the formatted addr value and service name.
func formatAddrService2(addr string, service string) string {
return addr + "/" + service
}
//****************************************************************
// Internal functions
//****************************************************************
// waitTillRunned will executed function in goroutine but will
// block till when goroutine is scheduled and started.
func waitTillRunned(fx func()) {
var w sync.WaitGroup
w.Add(1)
go func() {
w.Done()
fx()
}()
w.Wait()
}
// linearDoUntil will continuously run the giving function until no error is returned.
// If duration is supplied, the goroutine is made to sleep before making next run.
// The same duration is consistently used for each sleep.
func linearDoUntil(fx func() error, total int, elapse time.Duration) error {
var err error
for i := total; i > 0; i-- {
if err = fx(); err == nil {
return nil
}
if elapse > 0 {
time.Sleep(elapse)
}
}
return nil
}