forked from asynkron/protoactor-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware_chain.go
49 lines (41 loc) · 1.22 KB
/
middleware_chain.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
package actor
func makeReceiverMiddlewareChain(receiverMiddleware []ReceiverMiddleware, lastReceiver ReceiverFunc) ReceiverFunc {
if len(receiverMiddleware) == 0 {
return nil
}
h := receiverMiddleware[len(receiverMiddleware)-1](lastReceiver)
for i := len(receiverMiddleware) - 2; i >= 0; i-- {
h = receiverMiddleware[i](h)
}
return h
}
func makeSenderMiddlewareChain(senderMiddleware []SenderMiddleware, lastSender SenderFunc) SenderFunc {
if len(senderMiddleware) == 0 {
return nil
}
h := senderMiddleware[len(senderMiddleware)-1](lastSender)
for i := len(senderMiddleware) - 2; i >= 0; i-- {
h = senderMiddleware[i](h)
}
return h
}
func makeContextDecoratorChain(decorator []ContextDecorator, lastDecorator ContextDecoratorFunc) ContextDecoratorFunc {
if len(decorator) == 0 {
return nil
}
h := decorator[len(decorator)-1](lastDecorator)
for i := len(decorator) - 2; i >= 0; i-- {
h = decorator[i](h)
}
return h
}
func makeSpawnMiddlewareChain(spawnMiddleware []SpawnMiddleware, lastSpawn SpawnFunc) SpawnFunc {
if len(spawnMiddleware) == 0 {
return nil
}
h := spawnMiddleware[len(spawnMiddleware)-1](lastSpawn)
for i := len(spawnMiddleware) - 2; i >= 0; i-- {
h = spawnMiddleware[i](h)
}
return h
}