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

Side by Side 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, 7 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 *
3 * Copyright 2015-2016, Google Inc.
4 * All rights reserved.
3 * 5 *
4 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
6 * met: 8 * met:
7 * 9 *
8 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 12 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 13 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 14 * in the documentation and/or other materials provided with the
13 * distribution. 15 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 16 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 17 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 18 * this software without specific prior written permission.
17 * 19 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
29 */ 32 */
30 33
31 #ifndef WebSocketChannelClient_h 34 'use strict';
32 #define WebSocketChannelClient_h
33 35
34 #include "modules/ModulesExport.h" 36 var _ = require('lodash');
35 #include "platform/heap/Handle.h"
36 #include "wtf/Forward.h"
37 #include "wtf/PassOwnPtr.h"
38 #include "wtf/Vector.h"
39 #include <stdint.h>
40 37
41 namespace blink { 38 /**
39 * This class represents a queue of callbacks that must happen sequentially,
40 * each with a specific delay after the previous event.
41 */
42 function AsyncDelayQueue() {
43 this.queue = [];
42 44
43 class MODULES_EXPORT WebSocketChannelClient : public GarbageCollectedMixin { 45 this.callback_pending = false;
44 public: 46 }
45 virtual ~WebSocketChannelClient() { }
46 virtual void didConnect(const String& subprotocol, const String& extensions) { }
47 virtual void didReceiveTextMessage(const String&) { }
48 virtual void didReceiveBinaryMessage(PassOwnPtr<Vector<char>>) { }
49 virtual void didError() { }
50 virtual void didConsumeBufferedAmount(uint64_t consumed) { }
51 virtual void didStartClosingHandshake() { }
52 enum ClosingHandshakeCompletionStatus {
53 ClosingHandshakeIncomplete,
54 ClosingHandshakeComplete
55 };
56 virtual void didClose(ClosingHandshakeCompletionStatus, unsigned short /* co de */, const String& /* reason */) { }
57 DEFINE_INLINE_VIRTUAL_TRACE() { }
58 47
59 protected: 48 /**
60 WebSocketChannelClient() { } 49 * Run the next callback after its corresponding delay, if there are any
50 * remaining.
51 */
52 AsyncDelayQueue.prototype.runNext = function() {
53 var next = this.queue.shift();
54 var continueCallback = _.bind(this.runNext, this);
55 if (next) {
56 this.callback_pending = true;
57 setTimeout(function() {
58 next.callback(continueCallback);
59 }, next.delay);
60 } else {
61 this.callback_pending = false;
62 }
61 }; 63 };
62 64
63 } // namespace blink 65 /**
66 * Add a callback to be called with a specific delay after now or after the
67 * current last item in the queue or current pending callback, whichever is
68 * latest.
69 * @param {function(function())} callback The callback
70 * @param {Number} The delay to apply, in milliseconds
71 */
72 AsyncDelayQueue.prototype.add = function(callback, delay) {
73 this.queue.push({callback: callback, delay: delay});
74 if (!this.callback_pending) {
75 this.runNext();
76 }
77 };
64 78
65 #endif // WebSocketChannelClient_h 79 module.exports = AsyncDelayQueue;
OLDNEW
« 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