Simplify example

This commit is contained in:
Kegan Dougal 2016-12-09 16:28:41 +00:00
parent b8025f5f6d
commit 47da1cbcf2
1 changed files with 4 additions and 8 deletions

View File

@ -4,23 +4,19 @@ import (
"fmt" "fmt"
) )
func Example_blockingSync() { func Example_sync() {
cli, _ := NewClient("https://matrix.org", "@example:matrix.org", "MDAefhiuwehfuiwe") cli, _ := NewClient("https://matrix.org", "@example:matrix.org", "MDAefhiuwehfuiwe")
syncer := cli.Syncer.(*DefaultSyncer) syncer := cli.Syncer.(*DefaultSyncer)
syncer.OnEventType("m.room.message", func(ev *Event) { syncer.OnEventType("m.room.message", func(ev *Event) {
fmt.Println("Message: ", ev) fmt.Println("Message: ", ev)
}) })
// Blocking version
if err := cli.Sync(); err != nil { if err := cli.Sync(); err != nil {
fmt.Println("Sync() returned ", err) fmt.Println("Sync() returned ", err)
} }
}
func Example_nonBlockingSync() { // Non-blocking version
cli, _ := NewClient("https://matrix.org", "@example:matrix.org", "MDAefhiuwehfuiwe")
syncer := cli.Syncer.(*DefaultSyncer)
syncer.OnEventType("m.room.message", func(ev *Event) {
fmt.Println("Message: ", ev)
})
go func() { go func() {
for { for {
if err := cli.Sync(); err != nil { if err := cli.Sync(); err != nil {