代码拉取完成,页面将自动刷新
package actor
import (
"log/slog"
)
type Behavior []ReceiveFunc
func NewBehavior() Behavior {
return make(Behavior, 0)
}
func (b *Behavior) Become(receive ReceiveFunc) {
b.clear()
b.push(receive)
}
func (b *Behavior) BecomeStacked(receive ReceiveFunc) {
b.push(receive)
}
func (b *Behavior) UnbecomeStacked() {
b.pop()
}
func (b *Behavior) Receive(context Context) {
behavior, ok := b.peek()
if ok {
behavior(context)
} else {
context.Logger().Error("empty behavior called", slog.Any("pid", context.Self()))
}
}
func (b *Behavior) clear() {
if len(*b) == 0 {
return
}
for i := range *b {
(*b)[i] = nil
}
*b = (*b)[:0]
}
func (b *Behavior) peek() (v ReceiveFunc, ok bool) {
if l := b.len(); l > 0 {
ok = true
v = (*b)[l-1]
}
return
}
func (b *Behavior) push(v ReceiveFunc) {
*b = append(*b, v)
}
func (b *Behavior) pop() (v ReceiveFunc, ok bool) {
if l := b.len(); l > 0 {
l--
ok = true
v = (*b)[l]
(*b)[l] = nil
*b = (*b)[:l]
}
return
}
func (b *Behavior) len() int {
return len(*b)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。