代码拉取完成,页面将自动刷新
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()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。