39 lines
869 B
Go
39 lines
869 B
Go
package service
|
|
|
|
import (
|
|
"github.com/fox/fox/ipb"
|
|
"time"
|
|
)
|
|
|
|
type IService interface {
|
|
Name() string
|
|
Type() string
|
|
RunOnce(cb func())
|
|
RunWait(cb func() (retValue any)) (retValue any, err error)
|
|
|
|
NewTimer(duration time.Duration, cb func(), needLog bool, desc ...string) uint32
|
|
CancelTimer(timerId uint32)
|
|
CancelAllTimer()
|
|
|
|
// 向服务内部消息管道写入消息
|
|
Write(msg []byte) error
|
|
Send(topic string, msg *ipb.InternalMsg) error
|
|
Call(rpcTopic string, msg *ipb.InternalMsg, subMsg, cb any) error
|
|
|
|
WaitStop()
|
|
NotifyStop()
|
|
}
|
|
|
|
type ISender interface {
|
|
Send(topic string, msg *ipb.InternalMsg) error
|
|
Call(rpcTopic string, msg *ipb.InternalMsg, subMsg, cb any) error
|
|
}
|
|
|
|
type IOnFunc interface {
|
|
// 由子服务实现,比如玩法服需要等待所有玩家退出才能关闭服务
|
|
CanStop() bool
|
|
OnStop()
|
|
OnInit()
|
|
OnMessage(msg []byte) error
|
|
}
|