summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorraylu <raylu@mixpanel.com>2011-08-09 00:32:25 -0700
committerraylu <raylu@mixpanel.com>2011-08-09 00:34:00 -0700
commitdbf2f53eb6a3d0c49bd7585d8e9547dc8c57c95c (patch)
tree1ffb0743f03b7c60ac9ed3dd80b8a95228ae4b01
parent1cae243a08909eb3f0b1a8b3ffcf2f0769ab438f (diff)
downloadaudioaxis-dbf2f53eb6a3d0c49bd7585d8e9547dc8c57c95c.tar.xz
don't spam xhr's when there is an error or user stops
-rw-r--r--static/script.js16
-rw-r--r--templates/p.html4
-rw-r--r--updates.go2
3 files changed, 17 insertions, 5 deletions
diff --git a/static/script.js b/static/script.js
index d96650c..9513d59 100644
--- a/static/script.js
+++ b/static/script.js
@@ -1,3 +1,5 @@
+var current_id = '';
+var ids = [];
var player;
var litColor = '#eee';
var dimmedColor = '#555';
@@ -28,7 +30,18 @@ function getUpdates() {
dataType: 'json',
data: {pid: pid, timestamp: timestamp},
success: handleUpdates,
- complete: getUpdates
+ error: function (_, textStatus) {
+ switch (textStatus) {
+ case 'abort':
+ return;
+ case 'error':
+ case 'parsererror':
+ setTimeout(getUpdates, 1000);
+ return;
+ default:
+ getUpdates();
+ }
+ }
});
}
@@ -55,6 +68,7 @@ function handleUpdates(data) {
break;
}
}
+ getUpdates();
}
function drawBar(id) {
diff --git a/templates/p.html b/templates/p.html
index eb4dc80..79971c1 100644
--- a/templates/p.html
+++ b/templates/p.html
@@ -29,10 +29,8 @@
{{$first := "82KEVKGRAhI"}}
<script>
var pid = '{{.Id}}';
- var current_id = '';
- var ids = [];
</script>
- <script src="/static/jquery.min.js"></script>
+ <script src="/static/jquery.min.js"></script>
<!--
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
-->
diff --git a/updates.go b/updates.go
index 78db802..e0917cc 100644
--- a/updates.go
+++ b/updates.go
@@ -58,7 +58,7 @@ func addUpdate(pid int, action uint, song *Song) {
listeners[pid] = nil
}
-// assumes locked
+// assumes caller has updateLock
func checkUpdates(pid int, timestamp int64) *Update {
pup, _ := headUpdates[pid]
for pup != nil {