Skip to content

Commit 7b48e18

Browse files
authored
Unstable (anthdm#28)
* Fixed CPU usage caused by polling inboxes * fixed padding in ggq * README updates * doc fix * more doc updates and fixes * fixed bug where processes did not cleanup when reaching max restarts * Added SetOutput for the logger
1 parent bae4cfa commit 7b48e18

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test: build
2-
go test ./... --race
2+
go test ./... -count=1 --race
33

44
proto:
55
protoc --go_out=. --go-vtproto_out=. --go_opt=paths=source_relative --proto_path=. actor/actor.proto

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ e.Spawn(newFoo, "foo",
8585
)
8686
```
8787

88-
## Listening to the Eventstream
88+
## Subscribing and publishing to the Eventstream
8989

9090
```go
9191
e := actor.NewEngine()
9292

93-
// Subscribe to a various list of event that are being broadcasted by
94-
// the engine. But also published by you.
93+
// Subscribe to a various list of events that are being broadcast by
94+
// the engine.
95+
// The eventstream can also be used to publish custom events and notify all of the subscribers..
9596
eventSub := e.EventStream.Subscribe(func(event any) {
9697
switch evt := event.(type) {
9798
case *actor.DeadLetterEvent:
@@ -121,7 +122,7 @@ e.SpawnFunc(func(c *actor.Context) {
121122
time.Sleep(time.Second)
122123
```
123124

124-
## Customizing the PID separator
125+
## Customizing the Engine
125126

126127
```Go
127128
cfg := actor.Config{
@@ -132,7 +133,7 @@ e := actor.NewEngine(cfg)
132133

133134
After configuring the Engine with a custom PID Separator the string representation of PIDS will look like this:
134135

135-
```
136+
```Go
136137
pid := actor.NewPID("127.0.0.1:3000", "foo", "bar", "baz", "1")
137138
// 127.0.0.1:3000->foo->bar->baz->1
138139
```
@@ -147,15 +148,15 @@ For examples on how to implement custom middleware, check out the middleware fol
147148

148149
You can set the log level of Hollywoods log module:
149150

150-
```
151+
```Go
151152
import "github.com/anthdm/hollywood/log
152153
153154
log.SetLevel(log.LevelInfo)
154155
```
155156
156157
To disable all logging
157158
158-
```
159+
```Go
159160
import "github.com/anthdm/hollywood/log
160161

161162
log.SetLevel(log.LevelPanic)

actor/process.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (p *process) tryRestart(v any) {
132132
log.Errorw(msg.From, log.M{
133133
"error": msg.Err,
134134
})
135-
time.Sleep(restartDelay)
135+
time.Sleep(restartDelay) // TODO: make this configurable
136136
p.Start()
137137
return
138138
}
@@ -145,6 +145,7 @@ func (p *process) tryRestart(v any) {
145145
"pid": p.pid,
146146
"restarts": p.restarts,
147147
})
148+
p.cleanup(nil)
148149
return
149150
}
150151
// Restart the process after its restartDelay

examples/eventstream/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ func main() {
1212
wg := sync.WaitGroup{}
1313
wg.Add(1)
1414

15-
// Subscribe to a various list of event that are being broadcasted by
16-
// the engine. But also published by you.
15+
// Subscribe to a various list of events that are being broadcast by
16+
// the engine, but also published by you.
1717
eventSub := e.EventStream.Subscribe(func(event any) {
1818
switch evt := event.(type) {
1919
case *actor.DeadLetterEvent:

ggq/ggq.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type GGQ[T any] struct {
4040
state atomic.Uint32
4141
_ [cacheLinePadding - unsafe.Sizeof(atomic.Uint32{})]byte
4242
isIdling atomic.Bool
43+
_ [cacheLinePadding - unsafe.Sizeof(atomic.Bool{})]byte
4344
buffer []slot[T]
4445
_ [cacheLinePadding]byte
4546
mask uint32

log/log.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package log
22

3-
import "github.com/sirupsen/logrus"
3+
import (
4+
"io"
5+
6+
"github.com/sirupsen/logrus"
7+
)
48

59
type M map[string]any
610

@@ -16,6 +20,10 @@ const (
1620
LevelPanic
1721
)
1822

23+
func SetOutput(w io.Writer) {
24+
logrus.SetOutput(w)
25+
}
26+
1927
func SetLevel(level Level) {
2028
var l logrus.Level
2129
switch level {

0 commit comments

Comments
 (0)