Skip to content
This repository has been archived by the owner on Dec 30, 2019. It is now read-only.

Commit

Permalink
fix double-finish() issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bgilmore committed Nov 19, 2010
1 parent 166e83a commit 3009857
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion mailsink/static/index.html
Expand Up @@ -7,7 +7,7 @@
<script type="text/javascript" src="/sink.js"></script>
</head>
<body>
<div id="err">AN ERROR OCCURRED</div>
<div id="err"></div>
<ul id="messages"></ul>
<div id="splitter"></div>
<div id="viewer"></div>
Expand Down
20 changes: 17 additions & 3 deletions mailsink/static/sink.css
Expand Up @@ -9,6 +9,20 @@ html, body {

div#err {
display: none;

background-color: #fef0f0;
border: 1px solid #c00;
font-weight: bold;
font-size: 1.5em;
padding: 15px;
text-align: center;
text-transform: uppercase;

position: absolute;
top: 15px;
right: 15px;
left: 15px;
z-index: 1001;
}

ul#messages {
Expand All @@ -18,7 +32,7 @@ ul#messages {
margin: 0;
overflow: auto;
padding: 0;
width: 400px;
width: 375px;

position: absolute;
top: 0px;
Expand Down Expand Up @@ -82,7 +96,7 @@ div#splitter {
position: absolute;
top: 0;
bottom: 0;
left: 401px;
left: 376px;
}

div#viewer {
Expand All @@ -95,7 +109,7 @@ div#viewer {
top: 0;
right: 0;
bottom: 0;
left: 404px;
left: 379px;
}

div#viewer pre {
Expand Down
3 changes: 2 additions & 1 deletion mailsink/static/sink.js
Expand Up @@ -67,7 +67,8 @@ function poller() {
poller();
},
error: function() {
$('div#err').show();
$('div#err').text("Error: Lost connection to server")
.fadeIn();
}
});
}
Expand Down
15 changes: 10 additions & 5 deletions mailsink/webui.py
Expand Up @@ -40,14 +40,14 @@ class SinkStreamer(resource.Resource):

def __init__(self, root):
resource.Resource.__init__(self)
self._root = root
self._sink = root._sink

def render_GET(self, request):
d = defer.Deferred().addCallback(self._update, request)
self._d = defer.Deferred().addCallback(self._update, request)
timeout = reactor.callLater(10.0, self._timed_out, request)
self._root._sink.subscribe(d)
self._sink.subscribe(self._d)

request.notifyFinish().addBoth(self._finalize, d, timeout)
request.notifyFinish().addBoth(self._finalize, timeout)
return server.NOT_DONE_YET

def _update(self, message, request):
Expand All @@ -57,10 +57,15 @@ def _update(self, message, request):

def _timed_out(self, request):
# timed out with no activity
self._sink.unsub(self._d)
request.setResponseCode(204, "No Content")

request.finish()

def _finalize(self, _, d, timeout):
def _finalize(self, err, timeout):
if err is not None:
self._sink.unsub(self._d)

if timeout.active():
timeout.cancel()

Expand Down

0 comments on commit 3009857

Please sign in to comment.