github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/actor/middleware_chain.go (about) 1 package actor 2 3 func makeReceiverMiddlewareChain(receiverMiddleware []ReceiverMiddleware, lastReceiver ReceiverFunc) ReceiverFunc { 4 if len(receiverMiddleware) == 0 { 5 return nil 6 } 7 8 h := receiverMiddleware[len(receiverMiddleware)-1](lastReceiver) 9 for i := len(receiverMiddleware) - 2; i >= 0; i-- { 10 h = receiverMiddleware[i](h) 11 } 12 13 return h 14 } 15 16 func makeSenderMiddlewareChain(senderMiddleware []SenderMiddleware, lastSender SenderFunc) SenderFunc { 17 if len(senderMiddleware) == 0 { 18 return nil 19 } 20 21 h := senderMiddleware[len(senderMiddleware)-1](lastSender) 22 for i := len(senderMiddleware) - 2; i >= 0; i-- { 23 h = senderMiddleware[i](h) 24 } 25 26 return h 27 } 28 29 func makeContextDecoratorChain(decorator []ContextDecorator, lastDecorator ContextDecoratorFunc) ContextDecoratorFunc { 30 if len(decorator) == 0 { 31 return nil 32 } 33 34 h := decorator[len(decorator)-1](lastDecorator) 35 for i := len(decorator) - 2; i >= 0; i-- { 36 h = decorator[i](h) 37 } 38 39 return h 40 } 41 42 func makeSpawnMiddlewareChain(spawnMiddleware []SpawnMiddleware, lastSpawn SpawnFunc) SpawnFunc { 43 if len(spawnMiddleware) == 0 { 44 return nil 45 } 46 47 h := spawnMiddleware[len(spawnMiddleware)-1](lastSpawn) 48 for i := len(spawnMiddleware) - 2; i >= 0; i-- { 49 h = spawnMiddleware[i](h) 50 } 51 52 return h 53 }