2025-05-25 20:02:15 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2025-05-29 11:49:24 +08:00
|
|
|
"github.com/fox/fox/ipb"
|
2025-05-25 20:02:15 +08:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type IService interface {
|
|
|
|
Name() string
|
|
|
|
Type() string
|
|
|
|
RunOnce(cb func())
|
|
|
|
RunWait(cb func() (retValue any)) (retValue any, err error)
|
|
|
|
|
2025-06-07 12:13:12 +08:00
|
|
|
NewTimer(duration time.Duration, cb func(), needLog bool, desc ...string) uint32
|
|
|
|
CancelTimer(timerId uint32)
|
|
|
|
CancelAllTimer()
|
2025-05-25 20:02:15 +08:00
|
|
|
|
|
|
|
// 向服务内部消息管道写入消息
|
|
|
|
Write(msg []byte) error
|
2025-05-29 11:49:24 +08:00
|
|
|
Send(topic string, msg *ipb.InternalMsg) error
|
2025-06-01 09:57:01 +08:00
|
|
|
Call(rpcTopic string, timeout time.Duration, msg *ipb.InternalMsg) (*ipb.InternalMsg, error)
|
2025-05-25 20:02:15 +08:00
|
|
|
|
|
|
|
WaitStop()
|
|
|
|
NotifyStop()
|
|
|
|
}
|
|
|
|
|
|
|
|
type ISender interface {
|
2025-05-29 11:49:24 +08:00
|
|
|
Send(topic string, msg *ipb.InternalMsg) error
|
2025-06-01 09:57:01 +08:00
|
|
|
Call(rpcTopic string, timeout time.Duration, msg *ipb.InternalMsg) (*ipb.InternalMsg, error)
|
2025-05-25 20:02:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type IOnFunc interface {
|
2025-05-28 17:52:28 +08:00
|
|
|
// 由子服务实现,比如玩法服需要等待所有玩家退出才能关闭服务
|
|
|
|
CanStop() bool
|
2025-05-25 20:02:15 +08:00
|
|
|
OnStop()
|
|
|
|
OnInit()
|
|
|
|
OnMessage(msg []byte) error
|
|
|
|
}
|