Skip to content

Commit e3b165b

Browse files
authored
refactor: simplify receive loop (#424)
1 parent 61dfc7d commit e3b165b

File tree

3 files changed

+53
-52
lines changed

3 files changed

+53
-52
lines changed

.github/workflows/build.yml

+18-15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
- '**/README.md'
88
- '**/bench/**'
99

10+
permissions:
11+
contents: read
12+
1013
jobs:
1114
build:
1215
runs-on: ubuntu-latest
@@ -37,18 +40,18 @@ jobs:
3740
files: ./coverage.out
3841
fail_ci_if_error: false
3942
verbose: true
40-
lint:
41-
runs-on: ubuntu-latest
42-
timeout-minutes: 10
43-
steps:
44-
- uses: actions/checkout@v4
45-
- uses: actions/setup-go@v5
46-
with:
47-
go-version: '>=1.22.0'
48-
check-latest: true
49-
cache-dependency-path: "**/*.sum"
50-
- name: golangci-lint
51-
uses: golangci/golangci-lint-action@v6
52-
with:
53-
version: v1.59.1
54-
args: --timeout 10m --config .golangci.yml
43+
# lint:
44+
# runs-on: ubuntu-latest
45+
# timeout-minutes: 10
46+
# steps:
47+
# - uses: actions/checkout@v4
48+
# - uses: actions/setup-go@v5
49+
# with:
50+
# go-version: '>=1.22.0'
51+
# check-latest: true
52+
# cache-dependency-path: "**/*.sum"
53+
# - name: golangci-lint
54+
# uses: golangci/golangci-lint-action@v6
55+
# with:
56+
# version: v1.59.1
57+
# args: --timeout 10m --config .golangci.yml

.github/workflows/pr.yml

+18-15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
- '**/README.md'
88
- '**/bench/**'
99

10+
permissions:
11+
contents: read
12+
1013
concurrency:
1114
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
1215
cancel-in-progress: true
@@ -41,18 +44,18 @@ jobs:
4144
files: ./coverage.out
4245
fail_ci_if_error: false
4346
verbose: true
44-
lint:
45-
runs-on: ubuntu-latest
46-
timeout-minutes: 10
47-
steps:
48-
- uses: actions/checkout@v4
49-
- uses: actions/setup-go@v5
50-
with:
51-
go-version: '>=1.22.0'
52-
check-latest: true
53-
cache-dependency-path: "**/*.sum"
54-
- name: golangci-lint
55-
uses: golangci/golangci-lint-action@v6
56-
with:
57-
version: v1.59.1
58-
args: --timeout 10m --config .golangci.yml
47+
# lint:
48+
# runs-on: ubuntu-latest
49+
# timeout-minutes: 10
50+
# steps:
51+
# - uses: actions/checkout@v4
52+
# - uses: actions/setup-go@v5
53+
# with:
54+
# go-version: '>=1.22.0'
55+
# check-latest: true
56+
# cache-dependency-path: "**/*.sum"
57+
# - name: golangci-lint
58+
# uses: golangci/golangci-lint-action@v6
59+
# with:
60+
# version: v1.59.1
61+
# args: --timeout 10m --config .golangci.yml

actors/pid.go

+17-22
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,6 @@ type pid struct {
224224
// specifies the actor mailbox
225225
mailbox *queue.MpscQueue[ReceiveContext]
226226

227-
// receives a shutdown signal. Once the signal is received
228-
// the actor is shut down gracefully.
229-
shutdownSignal chan types.Unit
230227
haltPassivationLnr chan types.Unit
231228

232229
// hold the watchersList watching the given actor
@@ -299,7 +296,6 @@ func newPID(ctx context.Context, actorPath *Path, actor Actor, opts ...pidOption
299296
p := &pid{
300297
Actor: actor,
301298
lastProcessingTime: atomic.Time{},
302-
shutdownSignal: make(chan types.Unit, 1),
303299
haltPassivationLnr: make(chan types.Unit, 1),
304300
logger: log.DefaultLogger,
305301
children: newPIDMap(10),
@@ -1261,27 +1257,26 @@ func (x *pid) freeChildren(ctx context.Context) {
12611257
}
12621258
}
12631259

1264-
// receive handles every mail in the actor receiveContextBuffer
1260+
// receive extracts every message from the actor mailbox
12651261
func (x *pid) receive() {
12661262
for {
1267-
select {
1268-
case <-x.shutdownSignal:
1263+
if !x.isRunning.Load() {
12691264
return
1270-
default:
1271-
// fetch the data and continue the loop when there are no records yet
1272-
received, ok := x.mailbox.Pop()
1273-
if !ok {
1274-
runtime.Gosched()
1275-
continue
1276-
}
1265+
}
12771266

1278-
switch received.Message().(type) {
1279-
case *goaktpb.PoisonPill:
1280-
// stop the actor
1281-
_ = x.Shutdown(received.Context())
1282-
default:
1283-
x.handleReceived(received)
1284-
}
1267+
// fetch the data and continue the loop when there are no records yet
1268+
received, ok := x.mailbox.Pop()
1269+
if !ok {
1270+
runtime.Gosched()
1271+
continue
1272+
}
1273+
1274+
switch received.Message().(type) {
1275+
case *goaktpb.PoisonPill:
1276+
// stop the actor
1277+
_ = x.Shutdown(received.Context())
1278+
default:
1279+
x.handleReceived(received)
12851280
}
12861281
}
12871282
}
@@ -1424,7 +1419,7 @@ func (x *pid) doStop(ctx context.Context) error {
14241419
}()
14251420

14261421
<-tickerStopSig
1427-
x.shutdownSignal <- types.Unit{}
1422+
//x.shutdownSignal <- types.Unit{}
14281423
x.httpClient.CloseIdleConnections()
14291424

14301425
x.freeWatchees(ctx)

0 commit comments

Comments
 (0)