2 Star 0 Fork 0

比特虫洞/mails-pnp-driver

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pnp_service_impl.go 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
xukun 提交于 2024-06-17 12:04 . 实现了基本的 P&P 功能
package implements
import (
"context"
"time"
"gitee.com/bitwormhole/mails-pnp-driver/lib/pnp"
"gitee.com/bitwormhole/mails-pnp-driver/lib/web/vo"
"github.com/starter-go/application"
)
// PNPServiceImpl ...
type PNPServiceImpl struct {
//starter:component
_as func(pnp.Service) //starter:as("#")
channel chan vo.MessageJSON
}
func (inst *PNPServiceImpl) _impl() pnp.Service {
return inst
}
// Life ...
func (inst *PNPServiceImpl) Life() *application.Life {
return &application.Life{
OnCreate: inst.open,
OnDestroy: inst.close,
}
}
func (inst *PNPServiceImpl) open() error {
ch := make(chan vo.MessageJSON, 16)
inst.channel = ch
return nil
}
func (inst *PNPServiceImpl) close() error {
ch := inst.channel
inst.channel = nil
if ch != nil {
close(ch)
}
return nil
}
// Push ...
func (inst *PNPServiceImpl) Push(c context.Context, msg *vo.Message) error {
j := msg.ToJSON()
inst.channel <- j
return nil
}
// Pull ...
func (inst *PNPServiceImpl) Pull(c context.Context, timeout time.Duration) (*vo.Message, error) {
j := <-inst.channel
return j.ToMessage()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/bitwormhole/mails-pnp-driver.git
git@gitee.com:bitwormhole/mails-pnp-driver.git
bitwormhole
mails-pnp-driver
mails-pnp-driver
v0.0.1

搜索帮助