Created
March 3, 2020 22:07
-
-
Save chrishiestand/8bdcfed48d11c581629ad74f91dd6b82 to your computer and use it in GitHub Desktop.
Playing around with badger subscription
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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