Skip to content

Commit 0517429

Browse files
committed
Improve groovydoc
1 parent 84aeaab commit 0517429

File tree

1 file changed

+49
-41
lines changed

1 file changed

+49
-41
lines changed

src/main/groovy/org/grails/plugins/rx/web/RxResultSubscriber.groovy

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ import javax.servlet.http.HttpServletResponse
4343
@Slf4j
4444
class RxResultSubscriber extends Subscriber implements AsyncListener {
4545
/**
46-
* The Async context
46+
* The prefix for server sent events
4747
*/
4848
public static final String DATA_PREFIX = "data: "
49+
/**
50+
* The Async context
51+
*/
4952
final GrailsAsyncContext asyncContext
5053
/**
5154
* The exception handler
@@ -198,57 +201,62 @@ class RxResultSubscriber extends Subscriber implements AsyncListener {
198201

199202
@Override
200203
void onCompleted() {
201-
// When the observable finishes emitting items
202-
// terminate the asynchronous context in the appropriate manner based on the
203-
// completion strategy
204-
switch(completionStrategy) {
205-
case RxCompletionStrategy.COMPLETE:
206-
asyncContext.complete()
207-
break
208-
case RxCompletionStrategy.DISPATCH:
209-
asyncContext.dispatch()
210-
break
211-
case RxCompletionStrategy.NONE:
212-
// for none, the RxResult will have terminated the asynchronous context so do nothing
213-
break
214-
default:
215-
if(isRender) {
216-
asyncContext.response.flushBuffer()
217-
}
218-
asyncContext.complete()
204+
synchronized (asyncContext) {
205+
// When the observable finishes emitting items
206+
// terminate the asynchronous context in the appropriate manner based on the
207+
// completion strategy
208+
switch(completionStrategy) {
209+
case RxCompletionStrategy.COMPLETE:
210+
asyncContext.complete()
211+
break
212+
case RxCompletionStrategy.DISPATCH:
213+
asyncContext.dispatch()
214+
break
215+
case RxCompletionStrategy.NONE:
216+
// for none, the RxResult will have terminated the asynchronous context so do nothing
217+
break
218+
default:
219+
if(isRender) {
220+
asyncContext.response.flushBuffer()
221+
}
222+
asyncContext.complete()
223+
}
224+
219225
}
220226
}
221227

222228
@Override
223229
void onError(Throwable e) {
224-
if(!asyncComplete && !asyncContext.response.isCommitted()) {
225-
// if an error occurred and the response has not yet been commited try and handle it
226-
def httpServletResponse = (HttpServletResponse) asyncContext.response
227-
// first check if the exception resolver and resolve a model and view
228-
if(exceptionResolver != null) {
229-
def modelAndView = exceptionResolver.resolveException((HttpServletRequest) asyncContext.request, httpServletResponse, this, (Exception) e)
230-
if(modelAndView != null) {
231-
asyncContext.getRequest().setAttribute(GrailsApplicationAttributes.MODEL_AND_VIEW, modelAndView);
232-
asyncContext.dispatch()
230+
synchronized (asyncContext) {
231+
if(!asyncComplete && !asyncContext.response.isCommitted()) {
232+
// if an error occurred and the response has not yet been commited try and handle it
233+
def httpServletResponse = (HttpServletResponse) asyncContext.response
234+
// first check if the exception resolver and resolve a model and view
235+
if(exceptionResolver != null) {
236+
def modelAndView = exceptionResolver.resolveException((HttpServletRequest) asyncContext.request, httpServletResponse, this, (Exception) e)
237+
if(modelAndView != null) {
238+
asyncContext.getRequest().setAttribute(GrailsApplicationAttributes.MODEL_AND_VIEW, modelAndView);
239+
asyncContext.dispatch()
240+
}
241+
else {
242+
// if the error can't be resolved send the default error
243+
sendDefaultError(e, httpServletResponse)
244+
}
233245
}
234246
else {
235-
// if the error can't be resolved send the default error
236247
sendDefaultError(e, httpServletResponse)
237248
}
238249
}
239-
else {
240-
sendDefaultError(e, httpServletResponse)
241-
}
242-
}
243-
else if(!asyncComplete) {
244-
if(e != null) {
245-
log.error("Async Dispatch Error: ${e.message}", e)
246-
}
247-
else {
248-
log.debug("Async timeout occurred")
250+
else if(!asyncComplete) {
251+
if(e != null) {
252+
log.error("Async Dispatch Error: ${e.message}", e)
253+
}
254+
else {
255+
log.debug("Async timeout occurred")
256+
}
257+
asyncContext.request.removeAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE)
258+
asyncContext.complete()
249259
}
250-
asyncContext.request.removeAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE)
251-
asyncContext.complete()
252260
}
253261
}
254262

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