2016-12-09 16:09:48 +00:00
|
|
|
package gomatrix
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2016-12-09 16:16:45 +00:00
|
|
|
func Example_blockingSync() {
|
2016-12-09 16:09:48 +00:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
if err := cli.Sync(); err != nil {
|
|
|
|
fmt.Println("Sync() returned ", err)
|
|
|
|
}
|
|
|
|
}
|
2016-12-09 16:16:45 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|