Skip to content

Commit f58ef04

Browse files
committed
Document server sent event customization
1 parent a4f5d7e commit f58ef04

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/docs/asciidoc/serverSentEvents.adoc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,42 @@ function tickTock() {
7474
document.getElementById('message').innerHTML = event.data;
7575
}, false);
7676
}
77+
----
78+
79+
In addition for more complex event types you can use the `rx.event` method:
80+
81+
[source,groovy]
82+
----
83+
rx.stream { Subscriber subscriber ->
84+
for(i in (0..5)) {
85+
if(i % 2 == 0) {
86+
subscriber.onNext(
87+
rx.event("Tick", event:"Event $i", id:"$id", comment:"Tick Event") <1>
88+
)
89+
}
90+
else {
91+
...
92+
}
93+
}
94+
...
95+
}
96+
----
97+
98+
<1> The `event` method can be used to customize the Server Sent event properties and rendering multi-line data.
99+
100+
The `event` method also accepts `Writable` instances, which can be useful in combination with builders:
101+
102+
[source,groovy]
103+
----
104+
Writable writable = new Writable() {
105+
@Override
106+
Writer writeTo(Writer writer) throws IOException {
107+
new StreamingJsonBuilder(writer).call {
108+
tick "Tock"
109+
}
110+
return writer
111+
}
112+
}
113+
rx.event(writable, event:"Event $i", id:"$id", comment:"Tick Event")
114+
77115
----

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy