Skip to content

Commit dcf061e

Browse files
committed
cleanup
1 parent 8daa7f9 commit dcf061e

File tree

1 file changed

+38
-40
lines changed

1 file changed

+38
-40
lines changed

examples/server-sent-event-example/grails-app/controllers/rxjava/demo/TickTockController.groovy

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ class TickTockController implements RxController {
1818

1919
def index() {
2020
rx.stream { Subscriber emitter ->
21-
for(i in (0..5)) {
22-
if(i % 2 == 0) {
21+
for (i in (0..5)) {
22+
if (i % 2 == 0) {
2323
emitter.onNext(
24-
rx.render("Tick")
24+
rx.render("Tick")
2525
)
26-
}
27-
else {
26+
} else {
2827
emitter.onNext(
29-
rx.render("Tock")
28+
rx.render("Tock")
3029
)
3130

3231
}
@@ -42,13 +41,12 @@ class TickTockController implements RxController {
4241
log.info("Last Event ID: $lastId")
4342
rx.stream { Subscriber emitter ->
4443
log.info("SSE Thread ${Thread.currentThread().name}")
45-
for(i in (startId..(startId+9))) {
46-
if(i % 2 == 0) {
44+
for (i in (startId..(startId + 9))) {
45+
if (i % 2 == 0) {
4746
emitter.onNext(
4847
rx.event("Tick\n$i", id: i, event: 'tick', comment: 'tick')
4948
)
50-
}
51-
else {
49+
} else {
5250
emitter.onNext(
5351
rx.event("Tock\n$i", id: i, event: 'tock', comment: 'tock')
5452
)
@@ -64,23 +62,23 @@ class TickTockController implements RxController {
6462
def lastId = request.getHeader('Last-Event-ID') as Integer
6563
def startId = lastId ? lastId + 1 : 0
6664
rx.stream(
67-
Observable
68-
.interval(1, TimeUnit.SECONDS)
69-
.doOnSubscribe { log.info("Observable Subscribe Thread ${Thread.currentThread().name}") }
70-
.doOnNext { log.info("Observable Thread ${Thread.currentThread().name}") }
71-
.map {
72-
def id = it + startId
73-
def json = [type: 'observable', num: id] as JSON
65+
Observable
66+
.interval(1, TimeUnit.SECONDS)
67+
.doOnSubscribe { log.info("Observable Subscribe Thread ${Thread.currentThread().name}") }
68+
.doOnNext { log.info("Observable Thread ${Thread.currentThread().name}") }
69+
.map {
70+
def id = it + startId
71+
def json = [type: 'observable', num: id] as JSON
7472

75-
rx.event(new Writable() {
76-
@Override
77-
Writer writeTo(Writer writer) throws IOException {
78-
json.render(writer)
79-
return writer
80-
}
81-
}, id: id, comment: 'hello')
82-
}
83-
.take(10),
73+
rx.event(new Writable() {
74+
@Override
75+
Writer writeTo(Writer writer) throws IOException {
76+
json.render(writer)
77+
return writer
78+
}
79+
}, id: id, comment: 'hello')
80+
}
81+
.take(10)
8482
)
8583
}
8684

@@ -95,21 +93,21 @@ class TickTockController implements RxController {
9593

9694
def quartz() {
9795
rx.stream(
98-
publishedObservable
99-
.doOnSubscribe { log.info("Quartz Subscribe Thread ${Thread.currentThread().name}") }
100-
.doOnError { log.info("Quartz thread error") }
101-
.map {
102-
log.info("Quartz Thread ${Thread.currentThread().name}")
96+
publishedObservable
97+
.doOnSubscribe { log.info("Quartz Subscribe Thread ${Thread.currentThread().name}") }
98+
.doOnError { log.info("Quartz thread error") }
99+
.map {
100+
log.info("Quartz Thread ${Thread.currentThread().name}")
103101

104-
def json = [type: 'quartz', num: it as int] as JSON
105-
rx.event(new Writable() {
106-
@Override
107-
Writer writeTo(Writer writer) throws IOException {
108-
json.render(writer)
109-
return writer
110-
}
111-
}, comment: 'hello')
112-
}
102+
def json = [type: 'quartz', num: it as int] as JSON
103+
rx.event(new Writable() {
104+
@Override
105+
Writer writeTo(Writer writer) throws IOException {
106+
json.render(writer)
107+
return writer
108+
}
109+
}, comment: 'hello')
110+
}
113111
)
114112
}
115113
}

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