Index: third_party/grpc/src/node/interop/async_delay_queue.js |
diff --git a/third_party/WebKit/Source/modules/websockets/WebSocketChannelClient.h b/third_party/grpc/src/node/interop/async_delay_queue.js |
similarity index 56% |
copy from third_party/WebKit/Source/modules/websockets/WebSocketChannelClient.h |
copy to third_party/grpc/src/node/interop/async_delay_queue.js |
index 3777408a94bf73a68e31f78deee5b19948059344..df57209637620d55e9362a58c196616bc3893ef8 100644 |
--- a/third_party/WebKit/Source/modules/websockets/WebSocketChannelClient.h |
+++ b/third_party/grpc/src/node/interop/async_delay_queue.js |
@@ -1,5 +1,7 @@ |
/* |
- * Copyright (C) 2011 Google Inc. All rights reserved. |
+ * |
+ * Copyright 2015-2016, Google Inc. |
+ * All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions are |
@@ -26,40 +28,52 @@ |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * |
*/ |
-#ifndef WebSocketChannelClient_h |
-#define WebSocketChannelClient_h |
+'use strict'; |
-#include "modules/ModulesExport.h" |
-#include "platform/heap/Handle.h" |
-#include "wtf/Forward.h" |
-#include "wtf/PassOwnPtr.h" |
-#include "wtf/Vector.h" |
-#include <stdint.h> |
+var _ = require('lodash'); |
-namespace blink { |
+/** |
+ * This class represents a queue of callbacks that must happen sequentially, |
+ * each with a specific delay after the previous event. |
+ */ |
+function AsyncDelayQueue() { |
+ this.queue = []; |
-class MODULES_EXPORT WebSocketChannelClient : public GarbageCollectedMixin { |
-public: |
- virtual ~WebSocketChannelClient() { } |
- virtual void didConnect(const String& subprotocol, const String& extensions) { } |
- virtual void didReceiveTextMessage(const String&) { } |
- virtual void didReceiveBinaryMessage(PassOwnPtr<Vector<char>>) { } |
- virtual void didError() { } |
- virtual void didConsumeBufferedAmount(uint64_t consumed) { } |
- virtual void didStartClosingHandshake() { } |
- enum ClosingHandshakeCompletionStatus { |
- ClosingHandshakeIncomplete, |
- ClosingHandshakeComplete |
- }; |
- virtual void didClose(ClosingHandshakeCompletionStatus, unsigned short /* code */, const String& /* reason */) { } |
- DEFINE_INLINE_VIRTUAL_TRACE() { } |
+ this.callback_pending = false; |
+} |
-protected: |
- WebSocketChannelClient() { } |
+/** |
+ * Run the next callback after its corresponding delay, if there are any |
+ * remaining. |
+ */ |
+AsyncDelayQueue.prototype.runNext = function() { |
+ var next = this.queue.shift(); |
+ var continueCallback = _.bind(this.runNext, this); |
+ if (next) { |
+ this.callback_pending = true; |
+ setTimeout(function() { |
+ next.callback(continueCallback); |
+ }, next.delay); |
+ } else { |
+ this.callback_pending = false; |
+ } |
}; |
-} // namespace blink |
+/** |
+ * Add a callback to be called with a specific delay after now or after the |
+ * current last item in the queue or current pending callback, whichever is |
+ * latest. |
+ * @param {function(function())} callback The callback |
+ * @param {Number} The delay to apply, in milliseconds |
+ */ |
+AsyncDelayQueue.prototype.add = function(callback, delay) { |
+ this.queue.push({callback: callback, delay: delay}); |
+ if (!this.callback_pending) { |
+ this.runNext(); |
+ } |
+}; |
-#endif // WebSocketChannelClient_h |
+module.exports = AsyncDelayQueue; |