1 Star 2 Fork 0

李文建/light-protoactor-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
props.go 3.71 KB
一键复制 编辑 原始数据 按行查看 历史
李文建 提交于 2017-07-17 17:46 +08:00 . 1.git.oschina.net替换成gitee.com
package actor
import "gitee.com/lwj8507/light-protoactor-go/mailbox"
// Props represents configuration to define how an actor should be created
type Props struct {
actorProducer Producer
mailboxProducer mailbox.Producer
supervisionStrategy SupervisorStrategy
middleware []func(next ActorFunc) ActorFunc
middleware2 []func(next SenderFunc) SenderFunc
middlewareChain ActorFunc
middleware2Chain SenderFunc
dispatcher mailbox.Dispatcher
spawner SpawnFunc
}
func (props *Props) getDispatcher() mailbox.Dispatcher {
if props.dispatcher == nil {
return defaultDispatcher
}
return props.dispatcher
}
func (props *Props) getSupervisor() SupervisorStrategy {
if props.supervisionStrategy == nil {
return defaultSupervisionStrategy
}
return props.supervisionStrategy
}
func (props *Props) produceMailbox(invoker mailbox.MessageInvoker, dispatcher mailbox.Dispatcher) mailbox.Inbound {
if props.mailboxProducer == nil {
return defaultMailboxProducer(invoker, dispatcher)
}
return props.mailboxProducer(invoker, dispatcher)
}
func (props *Props) spawn(id string, parent *PID) (*PID, error) {
if props.spawner != nil {
return props.spawner(id, props, parent)
}
return DefaultSpawner(id, props, parent)
}
//WithMiddleware assigns one or more middlewares to the props
func (props *Props) WithMiddleware(middleware ...func(ActorFunc) ActorFunc) *Props {
props.middleware = append(props.middleware, middleware...)
props.middlewareChain = makeMiddlewareChain(props.middleware, localContextReceiver)
return props
}
func (props *Props) WithMiddleware2(middleware ...func(SenderFunc) SenderFunc) *Props {
props.middleware2 = append(props.middleware2, middleware...)
props.middleware2Chain = makeMiddleware2Chain(props.middleware2, localContextSender)
return props
}
//WithMailbox assigns the desired mailbox producer to the props
func (props *Props) WithMailbox(mailbox mailbox.Producer) *Props {
props.mailboxProducer = mailbox
return props
}
//WithSupervisor assigns a supervision strategy to the props
func (props *Props) WithSupervisor(supervisor SupervisorStrategy) *Props {
props.supervisionStrategy = supervisor
return props
}
//WithDispatcher assigns a dispatcher to the props
func (props *Props) WithDispatcher(dispatcher mailbox.Dispatcher) *Props {
props.dispatcher = dispatcher
return props
}
//WithSpawnFunc assigns a custom spawn func to the props, this is mainly for internal usage
func (props *Props) WithSpawnFunc(spawn SpawnFunc) *Props {
props.spawner = spawn
return props
}
//WithFunc assigns a receive func to the props
func (props *Props) WithFunc(f ActorFunc) *Props {
props.actorProducer = makeProducerFromInstance(f)
return props
}
//WithInstance creates a custom actor producer from a given instance and assigns it to the props
func (props *Props) WithInstance(a Actor) *Props {
props.actorProducer = makeProducerFromInstance(a)
return props
}
//WithProducer assigns a actor producer to the props
func (props *Props) WithProducer(p Producer) *Props {
props.actorProducer = p
return props
}
//FromProducer creates a props whith the given actor producer assigned
func FromProducer(actorProducer Producer) *Props {
return &Props{actorProducer: actorProducer}
}
//FromFunc creates a props with the given receive func assigned as the actor producer
func FromFunc(f ActorFunc) *Props {
return FromInstance(f)
}
//FromInstance creates a props with the given instance assigned as the actor producer
func FromInstance(template Actor) *Props {
return &Props{actorProducer: makeProducerFromInstance(template)}
}
func makeProducerFromInstance(a Actor) Producer {
return func() Actor {
return a
}
}
func FromSpawnFunc(spawn SpawnFunc) *Props {
return &Props{spawner: spawn}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/lwj8507/light-protoactor-go.git
git@gitee.com:lwj8507/light-protoactor-go.git
lwj8507
light-protoactor-go
light-protoactor-go
013e33d7022f

搜索帮助