Permalink
Browse files

Prevent the infinite spinner problem (where the page appears to load …

…forever

never completing), by attaching the EventSource after the page has loaded
with a javascript timeout handler.
  • Loading branch information...
1 parent a1b8396 commit 687eada953ca0de960f752705e5a8307825dd3f0 Rick Moynihan committed May 13, 2011
Showing with 12 additions and 14 deletions.
  1. +6 −1 files/index.html
  2. +6 −4 files/js/events.js
  3. +0 −9 src/sse/core.clj
View
@@ -1,7 +1,12 @@
<html>
<head>
</head>
-<body>
+<!--
+ To prevent the infinite spinner (page not completing) with the
+ use of the EventSource API you should call it after the page has
+ loaded, with a setTimeout.
+-->
+<body onload="setTimeout(attachEventSource,40)">
<h1>Server sent events example</h1>
<p>Run the server, by evaluating the sse.core namespace and visit
View
@@ -1,5 +1,7 @@
-var source = new EventSource('/event-source');
-source.onmessage = function (event) {
- alert(event.data);
-};
+var attachEventSource = function() {
+ var source = new EventSource('/event-source');
+ source.onmessage = function (event) {
+ alert(event.data);
+ };
+}
View
@@ -26,15 +26,6 @@
(wrap-file "./files")
(wrap-resource "./resources")))
-
-
(defonce server (start-http-server (wrap-ring-handler #'app) {:port 8080} ))
-(comment
- (defn stream-numbers [ch]
- (future
- (dotimes [i 10]
- (enqueue ch (str "data: " i "\n\n")))
- (enqueue-and-close ch nil))))
-

0 comments on commit 687eada

Please sign in to comment.