Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: third_party/grpc/src/node/interop/async_delay_queue.js

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/grpc/src/node/index.js ('k') | third_party/grpc/src/node/interop/interop_client.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « third_party/grpc/src/node/index.js ('k') | third_party/grpc/src/node/interop/interop_client.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698