Index: third_party/polymer/v0_8/components/polymer/src/lib/async.html |
diff --git a/third_party/polymer/v0_8/components/polymer/src/lib/async.html b/third_party/polymer/v0_8/components/polymer/src/lib/async.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..652bf53c821ffad00a91806a8871942ad101369e |
--- /dev/null |
+++ b/third_party/polymer/v0_8/components/polymer/src/lib/async.html |
@@ -0,0 +1,68 @@ |
+<!-- |
+@license |
+Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
+This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt |
+The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
+The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt |
+Code distributed by Google as part of the polymer project is also |
+subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt |
+--> |
+<script> |
+ |
+Polymer.Async = (function() { |
+ |
+ var currVal = 0; |
+ var lastVal = 0; |
+ var callbacks = []; |
+ var twiddle = document.createTextNode(''); |
+ |
+ function runAsync(callback, waitTime) { |
+ if (waitTime > 0) { |
+ return ~setTimeout(callback, waitTime); |
+ } else { |
+ twiddle.textContent = currVal++; |
+ callbacks.push(callback); |
+ return currVal - 1; |
+ } |
+ } |
+ |
+ function cancelAsync(handle) { |
+ if (handle < 0) { |
+ clearTimeout(~handle); |
+ } else { |
+ var idx = handle - lastVal; |
+ if (idx >= 0) { |
+ if (!callbacks[idx]) { |
+ throw 'invalid async handle: ' + handle; |
+ } |
+ callbacks[idx] = null; |
+ } |
+ } |
+ } |
+ |
+ function atEndOfMicrotask() { |
+ var len = callbacks.length; |
+ for (var i=0; i<len; i++) { |
+ var cb = callbacks[i]; |
+ if (cb) { |
+ cb(); |
+ } |
+ } |
+ callbacks.splice(0, len); |
+ lastVal += len; |
+ } |
+ |
+ new (window.MutationObserver || JsMutationObserver)(atEndOfMicrotask) |
+ .observe(twiddle, {characterData: true}) |
+ ; |
+ |
+ // exports |
+ |
+ return { |
+ run: runAsync, |
+ cancel: cancelAsync |
+ }; |
+ |
+})(); |
+ |
+</script> |