diff --git a/example_test.go b/example_test.go index 557f2b8..1f463fe 100644 --- a/example_test.go +++ b/example_test.go @@ -4,14 +4,29 @@ import ( "fmt" ) -func Example() { +func Example_blockingSync() { 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) }) - // To make the example non-blocking, call Sync() in a goroutine. if err := cli.Sync(); err != nil { fmt.Println("Sync() returned ", err) } } + +func Example_nonBlockingSync() { + 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() { + for { + if err := cli.Sync(); err != nil { + fmt.Println("Sync() returned ", err) + } + // Optional: Wait a period of time before trying to sync again. + } + }() +}