Skip to content

Instantly share code, notes, and snippets.

@chrishiestand
Created March 3, 2020 22:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrishiestand/8bdcfed48d11c581629ad74f91dd6b82 to your computer and use it in GitHub Desktop.
Save chrishiestand/8bdcfed48d11c581629ad74f91dd6b82 to your computer and use it in GitHub Desktop.
Playing around with badger subscription
package main
import (
"context"
"fmt"
"log"
badger "github.com/dgraph-io/badger/v2"
"github.com/dgraph-io/badger/v2/pb"
)
func main() {
log.Println("starting")
db, err := badger.Open(badger.DefaultOptions("../../dgraph-tutorial/p"))
if err != nil {
log.Fatal(err)
}
defer db.Close()
// Your code here…
ctx := context.Background()
ch := make(chan struct{})
handleSubscription := func(kvl *pb.KVList) error {
panic("AAAAAAAHHH")
for _, kv := range kvl.GetKv() {
fmt.Println(string(kv.GetKey()), string(kv.GetValue()))
}
ch <- struct{}{}
return nil
}
err = db.Subscribe(ctx, handleSubscription, []byte{})
if err != nil {
fmt.Println(err)
}
log.Println("opened?")
<-ch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment