1 Star 0 Fork 0

jack/protoactor-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
provider.go 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
jack 提交于 2024-11-27 09:43 . 新建自定义分支
package protocb
import (
"log"
"time"
"gitee.com/wujianhai/protoactor-go/actor"
"gitee.com/wujianhai/protoactor-go/persistence"
"github.com/couchbase/gocb"
)
type Provider struct {
async bool
bucket *gocb.Bucket
bucketName string
snapshotInterval int
writer *actor.PID
}
func (provider *Provider) GetState() persistence.ProviderState {
return &cbState{
Provider: provider,
}
}
func New(actorSystem *actor.ActorSystem, bucketName string, baseU string, options ...CouchbaseOption) *Provider {
c, err := gocb.Connect(baseU)
if err != nil {
log.Fatalf("Error connecting: %v", err)
}
bucket, err := c.OpenBucketWithMt(bucketName, "")
if err != nil {
log.Fatalf("Error getting bucket: %v", err)
}
bucket.SetTranscoder(transcoder{})
config := &couchbaseConfig{}
for _, option := range options {
option(config)
}
provider := &Provider{
snapshotInterval: config.snapshotInterval,
async: config.async,
bucket: bucket,
bucketName: bucketName,
}
if config.async {
pid := actorSystem.Root.Spawn(actor.PropsFromFunc(newWriter(time.Second / 10000)))
provider.writer = pid
}
return provider
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wujianhai/protoactor-go.git
git@gitee.com:wujianhai/protoactor-go.git
wujianhai
protoactor-go
protoactor-go
99a34e4ec9eb

搜索帮助