mirror of https://github.com/matrix-org/gomatrix
Simplify example
This commit is contained in:
parent
b8025f5f6d
commit
47da1cbcf2
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue