mirror of https://github.com/matrix-org/gomatrix
Sync examples
This commit is contained in:
parent
76fa23b9a4
commit
e989121b7a
|
@ -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.
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue