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

Side by Side Diff: mojo/public/js/new_bindings/connector.js

Issue 2744943002: Mojo: Move waiting APIs to public library (Closed)
Patch Set: . Created 3 years, 9 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 | « mojo/public/js/core.js ('k') | mojo/public/js/tests/core_unittest.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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 define("mojo/public/js/connector", [ 5 define("mojo/public/js/connector", [
6 "mojo/public/js/buffer", 6 "mojo/public/js/buffer",
7 "mojo/public/js/codec", 7 "mojo/public/js/codec",
8 "mojo/public/js/core", 8 "mojo/public/js/core",
9 "mojo/public/js/support", 9 "mojo/public/js/support",
10 ], function(buffer, codec, core, support) { 10 ], function(buffer, codec, core, support) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 Connector.prototype.setErrorHandler = function(handler) { 77 Connector.prototype.setErrorHandler = function(handler) {
78 this.errorHandler_ = handler; 78 this.errorHandler_ = handler;
79 }; 79 };
80 80
81 Connector.prototype.encounteredError = function() { 81 Connector.prototype.encounteredError = function() {
82 return this.error_; 82 return this.error_;
83 }; 83 };
84 84
85 Connector.prototype.waitForNextMessageForTesting = function() { 85 Connector.prototype.waitForNextMessageForTesting = function() {
86 var wait = core.wait(this.handle_, core.HANDLE_SIGNAL_READABLE, 86 var wait = core.wait(this.handle_, core.HANDLE_SIGNAL_READABLE);
87 core.DEADLINE_INDEFINITE);
88 this.readMore_(wait.result); 87 this.readMore_(wait.result);
89 }; 88 };
90 89
91 Connector.prototype.readMore_ = function(result) { 90 Connector.prototype.readMore_ = function(result) {
92 for (;;) { 91 for (;;) {
93 var read = core.readMessage(this.handle_, 92 var read = core.readMessage(this.handle_,
94 core.READ_MESSAGE_FLAG_NONE); 93 core.READ_MESSAGE_FLAG_NONE);
95 if (this.handle_ == null) // The connector has been closed. 94 if (this.handle_ == null) // The connector has been closed.
96 return; 95 return;
97 if (read.result == core.RESULT_SHOULD_WAIT) 96 if (read.result == core.RESULT_SHOULD_WAIT)
98 return; 97 return;
99 if (read.result != core.RESULT_OK) { 98 if (read.result != core.RESULT_OK) {
100 this.error_ = true; 99 this.error_ = true;
101 if (this.errorHandler_) 100 if (this.errorHandler_)
102 this.errorHandler_.onError(read.result); 101 this.errorHandler_.onError(read.result);
103 return; 102 return;
104 } 103 }
105 var messageBuffer = new buffer.Buffer(read.buffer); 104 var messageBuffer = new buffer.Buffer(read.buffer);
106 var message = new codec.Message(messageBuffer, read.handles); 105 var message = new codec.Message(messageBuffer, read.handles);
107 if (this.incomingReceiver_) 106 if (this.incomingReceiver_)
108 this.incomingReceiver_.accept(message); 107 this.incomingReceiver_.accept(message);
109 } 108 }
110 }; 109 };
111 110
112 var exports = {}; 111 var exports = {};
113 exports.Connector = Connector; 112 exports.Connector = Connector;
114 return exports; 113 return exports;
115 }); 114 });
OLDNEW
« no previous file with comments | « mojo/public/js/core.js ('k') | mojo/public/js/tests/core_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698